• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

better ways to truncate a double

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Gday, Previously I have been trying to find a method easily truncate a double to a fixed number of decimal places, rounding in the traditional grade school style. Tried big decimal classes and all but There was no reaql easy way to get the required end result. What I have implemented and am using (although inefficient) is Multiplying the double by 10^(number of required places + 1), turn into integer,finding the remainder after dividing by 10, adding or subtracting the appropriate amount, turning into a string then manually inserting a decimal point and zeros if required then returning String.toDouble(). This works perfectly but there must be an easier way?. B. Till
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic