How to round up / round down / round nearest the values?

Hi,

How to round up / round down / round nearest the values? Can anyone help to start somewhere ?

If the amount is = 3333.35 thenExpected Out Put-------------------------Round Exact:---------------------Round to Exact = $ 3333.35Round to $1 = $ 3333Round to $10 = $ 3330Round to $100 = $ 3300Round to $1000 = $ 3000Round Up-----------------------Round to Exact = $ 3333.35Round to $1 = $ 3334Round to $10 = $ 3340Round to $100 = $ 3400Round to $1000 = $ 4000Round Down----------------------------------Round to Exact = $ 3333.35Round to $1 = $ 3333Round to $10 = $ 3330Round to $100 = $ 3300Round to $1000 = $ 3000Round nearest---------------------------Round to Exact = $ 3333.35Round to $1 = $ 3333Round to $10 = $ 3330Round to $100 = $ 3300Round to $1000 = $ 3000

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Also notice the pattern
document.write ("\nRound to $10 = \t\t\$" + Math.round(amount/10)*10 + "\n");
since we are rounding to the nearest 10.00
we need to divide by 10.00
round
then multiply by 10

The same pattern exist for all lines:
document.write ("\nRound to Exact = \t\$" + Math.round(amount*100)/100 + "\n");
since we are rounding to the nearest .01
we need to divide by 0.01 (or multiply by 100 in algebraical terms)
round
then multiply by 0.01 (or divide by 100 in algebraical terms)

Therefore, for complete uniform pattern sake you could have written this instead:
document.write ("\nRound to Exact = \t\$" + Math.round(amount/0.01)*0.01 + "\n");
since it is the same as
document.write ("\nRound to Exact = \t\$" + Math.round(amount*100)/100 + "\n");

Thus,
the formula is:
Math.Round(amount / precision) * precision
So if you wanted 123456789 to the nearest 100,000.

amount=123456789;precision=100000;document.write (Math.round(amount / precision)*precision);//output is 123500000

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

floor (round down)

round (round 4/5)