How would I round 14.600000000001 into just 14.6? The user inputs a number(double), then the program will spit the calculation out.
Printable View
How would I round 14.600000000001 into just 14.6? The user inputs a number(double), then the program will spit the calculation out.
Typically there two ways of producing a human friendly string from a floating point value like a double: have a look at the DecimalFormat class and the format() method of String. (PrintStream instances like System.out have a printf() method which is simlar to the latter)
Sorry, I realise I didn't *exactly* address what you asked. Almost always it's a human friendly string that's wanted and not a - necessarily *less* accurate - floating point value. Rounding in this sense is problematic, not least because it's not at all obvious that Java floating point values are even capable of unambiguously representing the matgematical magnitude 14.6 together with it's infinity of trailling zeros.
My output is 14.6000000001. How would I change it to only output 14.6?