Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NumberFormatException: For input string: "48,09" #134

Open
akardas16 opened this issue Aug 20, 2023 · 2 comments
Open

NumberFormatException: For input string: "48,09" #134

akardas16 opened this issue Aug 20, 2023 · 2 comments

Comments

@akardas16
Copy link

I clone the project and when I run it on my device, app crashed in a few activities. the issue is related to string conversion to float.
As you see below value from Random.nextDouble(1.0, maxRange.toDouble()) is 48.088231731515215 but formating will cause to change point (.) to comma (,). this could be related to device language because we use comma for decimals in Turkish.
val barValue = "%.2f".format(Random.nextDouble(1.0, maxRange.toDouble())).toFloat()

getGroupBarChartData: 48.088231731515215 2023-08-21 00:34:23.560 10199-10199 AndroidRuntime co.yml.ycharts.app D Shutting down VM 2023-08-21 00:34:23.561 10199-10199 AndroidRuntime co.yml.ycharts.app E FATAL EXCEPTION: main Process: co.yml.ycharts.app, PID: 10199 java.lang.NumberFormatException: For input string: "48,09" at jdk.internal.math.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:2054) at jdk.internal.math.FloatingDecimal.parseFloat(FloatingDecimal.java:122) at java.lang.Float.parseFloat(Float.java:455) at co.yml.charts.common.utils.DataUtils.getGroupBarChartData(DataUtils.kt:341) at co.yml.ycharts.app.presentation.CombinedLineAndBarChartActivityKt.BarWithLineChart(CombinedLineAndBarChartActivity.kt:104) at co.yml.ycharts.app.presentation.CombinedLineAndBarChartActivity$onCreate$1$1$2$1$1$1$1.invoke(CombinedLineAndBarChartActivity.kt:76) at co.yml.ycharts.app.presentation.CombinedLineAndBarChartActivity$onCreate$1$1$2$1$1$1$1.invoke(CombinedLineAndBarChartActivity.kt:67) at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:135)

@kongstedet
Copy link

A simple hack is to edit four lines in DataUtils by adding a replace() call:

                    "%.2f".format(Random.nextDouble(1.0, maxRange.toDouble())).replace(',','.').toFloat(),

This simply brings the european (and other) comma-format back to the dot-format that 'toFloat' expects.

@akardas16
Copy link
Author

akardas16 commented Nov 14, 2023

A simple hack is to edit four lines in DataUtils by adding a replace() call:

                    "%.2f".format(Random.nextDouble(1.0, maxRange.toDouble())).replace(',','.').toFloat(),

This simply brings the european (and other) comma-format back to the dot-format that 'toFloat' expects.

Why is that happen? Is that kotlin/java bug?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants