Miscellaneous > Programming & Networking

Need help with formatting numbers in java

(1/1)

Xeen:
say I have the numbers:

float x = 1.23456  
and
double y = 4.5678

How do I get them to be rounded off to the nearest tenth? (x should become 1.2 and y should become 4.6). ?

I know how this is done in C/C++, but I can't figure it out in java.

flap:
Math.round(f*10)/10f

Navigation

[0] Message Index

Go to full version