• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

howto round integer ?

 
Nakata kokuyo
Ranch Hand
Posts: 465
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi, good day, if i have a integer number = "1234567" , and i would like to round the last 2 digit , means if last 2 digit more than 50, it will become "1234600"

if we hv integer number "1234535" , it will round to 1234500, cause the last 2 digit is less than 50 ,

in my case, how to i round that ? is API have class to cater these numbering ?

thank you for guidance
 
vignesh hariharan
Ranch Hand
Posts: 77
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am not sure if your question is correct. i think it is 12345.67 which will be rounded to 12346 and 12345.35 will be rounded to 12345

correct me if i am wrong.
 
Roy Simon
Ranch Hand
Posts: 62
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
You want to round off integers??
i dont think the java Api offers anything of that sort and moreover its very simple..
1.Create a custom class with an Integer Object....
2.Create objects of the custom class by passing integers into the constructor...
3. Inside the constructor u can use the %50 operator and additional code to either add or truncate the tail...
Now u get the required functionality
U can use the intValue() method of the Integer class to get an int from the Integer!!
Hope this helps...

Regards
Simon
[ April 01, 2006: Message edited by: Roy Simon ]
 
Paul Santa Maria
Ranch Hand
Posts: 236
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd suggest:
i = (int)((num / 100.0) + 0.5) * 100;
 
Nakata kokuyo
Ranch Hand
Posts: 465
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Santa Maria , it look like good solution and simpler , at the moment, i just try on this as roy mentioned , here is my sample code

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic