A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Win a copy of
Badass: Making Users Awesome
this week in the
Round to n decimals?
Joined: Nov 29, 2009
Dec 23, 2009 08:50:43
How does one round(123.456) to 123.46?
Everything I've found so far says
returns a whole number, so round(123.45) returns 123. The languages I'm most fluent in have a
round(value, number of decimals)
function to handle this.
I expect I either haven't run across it yet or haven't looked in the right place.
FYI, I've been programming for close to 25+ years (Progress, 4GL/ABL) but new to
. I'm hoping to complete my
in the not too distant future.
Carlson Consulting, Inc.
Joined: Mar 20, 2007
Dec 23, 2009 09:02:35
look at the class
and the setScale() method
Joined: Oct 27, 2005
Dec 23, 2009 09:14:34
An alternative is multiply by 100, then round, then divide by 100 again.
is better (and more accurate) though.
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions
How To Answer Questions
I agree. Here's the link:
subject: Round to n decimals?
Problem while executing the program
cut off decimals of a float number
creating a calculator application - need some math help
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2015