• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

howto round integer ?

 
Ranch Hand
Posts: 472
  • 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
 
Ranch Hand
Posts: 77
  • 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.
 
Ranch Hand
Posts: 62
  • 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 ]
 
Ranch Hand
Posts: 236
  • 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: 472
  • 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

 
This is awkward. I've grown a second evil head. I'm going to need a machete and a tiny ad ...
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
    Bookmark Topic Watch Topic
  • New Topic