Stop Microsoft
Welcome,
Guest
. Please
login
or
register
.
Have you missed your
activation email
?
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length.
News:
Home
Help
Login
Register
Stop Microsoft
»
Miscellaneous
»
Programming & Networking
»
Need help with formatting numbers in java
« previous
next »
Print
Pages: [
1
]
Go Down
Author
Topic: Need help with formatting numbers in java (Read 1381 times)
Xeen
VIP
Member
Posts: 1,065
Kudos: 55
Need help with formatting numbers in java
«
on:
15 June 2004, 20:36 »
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.
Logged
flap
Member
Posts: 1,268
Kudos: 137
Need help with formatting numbers in java
«
Reply #1 on:
15 June 2004, 22:18 »
Math.round(f*10)/10f
Logged
"While envisaging the destruction of imperialism, it is necessary to identify its head, which is none other than the United States of America." - Ernesto Che Guevara
http://counterpunch.org
http://globalresearch.ca
Print
Pages: [
1
]
Go Up
« previous
next »
Stop Microsoft
»
Miscellaneous
»
Programming & Networking
»
Need help with formatting numbers in java