+ 1
How to round this to two significant decimal figure?
8 Respostas
+ 21
Forgot to save the changes :(
https://code.sololearn.com/cwqSch5c8Sia/?ref=app
+ 20
In addition to T0nd3's answer, you can also return the result as string using String.format(). Or return as double and then print using printf() method. Both the ways have been shown here :
[EDIT]:
https://code.sololearn.com/cwqSch5c8Sia/?ref=app
+ 2
you can use:
double pi = Math.PI;
DecimalFormat decimalFormat = new DecimalFormat(",##0.00");
System.err.println(pi);
System.err.println(decimalFormat.format(pi));
by adding 0 behind the "." you get more digits
+ 2
or you can just convert double to float to keep the code simple :0
https://code.sololearn.com/cdzXp900UyIL/?ref=app
+ 2
OK here you go...
simple just add these two line to your code
//float b=(float)a;
String s = String.format("%.2f", b);
https://code.sololearn.com/cdzXp900UyIL/?ref=app
+ 1
shamima and shikamaru why is your code not working is there any import function to include?
+ 1
try again john it works fine..
and I just added this one line to your code
//float b=(float)a;
+ 1
OK Shikamaru but this ain't 2 significant decimal