Author Topic: Need help with formatting numbers in java  (Read 1308 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.

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
"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