This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes JDBC and the fly likes better ways to truncate a double Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Databases » JDBC
Reply Bookmark "better ways to truncate a double" Watch "better ways to truncate a double" New topic
Author

better ways to truncate a double

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
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
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: better ways to truncate a double
 
Similar Threads
Truncate a String
How to find number of decimal places?
Number Format Specifiers
How to count the number of digits after decimal point in java?
double precision