gpt4 book ai didi

java - NumberFormatException 对于法语输入字符串

转载 作者:太空宇宙 更新时间:2023-11-04 10:13:09 25 4
gpt4 key购买 nike

我遇到了 NumberFormatException 的问题。用于法语的输入字符串。当我选择英语/西类牙语时,一切正常!但是当我立即选择法语时,它崩溃并显示 NFException .

public void TemperatureCurrentLevel(DosageCalculatorInputDto dosagecalculatorinput, DosageCalculatorResponseDto dosageCalculatorResponseDto) {
double temp = dosagecalculatorinput.getTemperatureNow();
Log.e("temp value", ""+Double.parseDouble(String.format("%.2f", Math.pow(temp, 3))));
double power3 = Double.parseDouble(String.format("%.2f", Math.pow(temp, 3)));
double power2 = Double.parseDouble(String.format("%.2f", Math.pow(temp, 2)));
Double result = (-0.0000005 * power3 + 0.00006 * power2 + 0.0117 * temp - 0.4116);
Log.i("teja1", "temperature factor current " + Double.parseDouble(String.format("%.3f", result)));

dosageCalculatorResponseDto.setTemparatureFactoreCurrent( result);
}

Logcat:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.elitecrest.orenda/com.elitecrest.orenda.MainActivity}: java.lang.NumberFormatException: For input string: "512000,00"
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2721)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2782)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1521)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:163)
at android.app.ActivityThread.main(ActivityThread.java:6228)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
Caused by: java.lang.NumberFormatException: For input string: "512000,00"
at java.lang.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1306)
at java.lang.Double.parseDouble(Double.java:547)
at com.elitecrest.orenda.utils.FormulationClass.TemperatureCurrentLevel(FormulationClass.java:64)

我遇到了 power3 的问题值(value)。对于英语/西类牙语,其值为 512000.0,但对于法语,其值为 512000,00

最佳答案

尝试使用replace():

 Double.parseDouble(String.format("%.2f", Math.pow(temp, 3)).replace(',', '.'))

关于java - NumberFormatException 对于法语输入字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52070943/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com