DecimalFormat not formatting my numbers correctly
-
23-02-2021 - |
Pregunta
I want to round all of my numbers to 1 decimal place.
For example
22.0
-6.1
I am using:
DecimalFormat decimalFormat = new DecimalFormat("0.0");
middlePanelTextView.setText(decimalFormat.format(score.getElevationAngle()));
But whole numbers don't have a 0 appended to it.
-18 should be -18.0 etc.
instead my value shows up as -18.
Solución 3
My TextView was cutting off the digits. My fault. Shrank font size.
Otros consejos
.@ represents a significant digit 0 doesn't.
.# represents and optional digit So try "##@.@"
http://developer.android.com/reference/java/text/DecimalFormat.html
I'm not sure about the syntax: but the above article should give you all you need.
Try
middlePanelTextView.setText(""+decimalFormat.format(score.getElevationAngle()));
Try using
DecimalFormat decimalFormat = new DecimalFormat("#.#");
as the constructor parameter instead.
Try using the following code:
DecimalFormat decimalFormat = new DecimalFormat("0.0#");
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow