Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Rounding up numbers in Java

Status
Not open for further replies.

dio2449

Newbie level 4
Joined
Oct 14, 2009
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,321
I have a Java program that returns a result.What I want is if the result is,for example,equal to 127 to be rounded to 130,if it's 231 to make it 240 and so on.How can I do this?
 

Maybe divide by 10 then add one and then multiply by ten.
 

Do you know why it works?

---------- Post added at 20:03 ---------- Previous post was at 19:58 ----------

Actually it will not work if you have round numbers like 120 or 130 or 230 etc.

You should use the modulo operator to avoid getting wrong result.
In round numbers you'll get 140 for 130 or 200 for 190 etc

use:
Code:
if (number %10) >0
.....
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top