| Author |
Round a decimal Number
|
Sam Saha
Ranch Hand
Joined: Jan 23, 2010
Posts: 89
|
|
|
I have a decimal number like 25.7575757578. When I use Math.round(25.7575757578) I am getting the output 16. But I wanted to get the output 15 instead of 16. Can someone suggest me if it is possible to do that. Thank you very much.
|
 |
Sam Saha
Ranch Hand
Joined: Jan 23, 2010
Posts: 89
|
|
Sorry, there was a typo mistake.
I have a decimal number like155.727911726. When I use Math.round(155.727911726/10) I am getting the output 16. But I wanted to get the output 15 instead of 16. Can someone suggest me if it is possible to do that. Thank you very much.
|
 |
Richard Tookey
Ranch Hand
Joined: Aug 27, 2012
Posts: 362
|
|
Sam Saha wrote:Sorry, there was a typo mistake.
I have a decimal number like155.727911726. When I use Math.round(155.727911726/10) I am getting the output 16. But I wanted to get the output 15 instead of 16. Can someone suggest me if it is possible to do that. Thank you very much.
It is not clear to me what you are trying to but if you are wanting to round down to the lower integer then just use
( (int) 155.727911726) / 10
but this will fail for numbers greater than Integer.MAX_VALUE and may not be what you want for negative values.
|
 |
Winston Gutkowski
Bartender
Joined: Mar 17, 2011
Posts: 4761
|
|
Sam Saha wrote:Sorry, there was a typo mistake.
Actually, neither of your posts makes much sense, but my advice would be to look at Math.floor().
Oh, and BTW, what you're doing is not rounding; it's truncating.
Winston
|
Isn't it funny how there's always time and money enough to do it WRONG?
|
 |
Richard Tookey
Ranch Hand
Joined: Aug 27, 2012
Posts: 362
|
|
Winston Gutkowski wrote:
Sam Saha wrote:Sorry, there was a typo mistake.
Actually, neither of your posts makes much sense, but my advice would be to look at Math.floor().
Oh, and BTW, what you're doing is not rounding; it's truncating.
Winston
++
:-))) I feel silly now !
|
 |
 |
|
|
subject: Round a decimal Number
|
|
|