Reputation: 1567
I have jdouble(double) value coming in from my activity which when printed gives in scientific notation i.e in E format. Now i want to show it in decimal format and truncate it so i used "%.2f" in my format specifier to do that. But weirdly the "%f" format specifier is showing 0.000000 as the final value. please suggest some advice.
P.S I'm doing this on the native side of android.
Upvotes: 0
Views: 312
Reputation: 304
In order to show decimals instead of E format notation and truncate a number you can use NumberFormat:
NumberFormat formatter = new DecimalFormat("#0.000");
An then, where you want to use your number:
formatter.format(yournumber)
e.g.:
Toast.makeText(context, "Truncated number: " + formatter.format(yournumber), Toast.LENGTH_LONG).show();
In this case, your number will be shown with 3 decimals. Add as many zeros as decimals you want to show.
Upvotes: 1