How to write "0" rounded to two decimal places??

2.1k Views Asked by At

I'm working on some function that rounds a number to specific decimal places, and I want to ask; what if we have an output that has decimal places less than required. e.g. "$1.002$" rounded to two decimal places, will be "$1$" or "$1.00$" and also "$0$" (zero) rounded to two decimal places, will be "$0$" or "$0.00$". thanks :)

1

There are 1 best solutions below

0
On BEST ANSWER

Usually the following rule is adopted:

consider: $N=1.00abcd...$

set: $X=(N-1)1000=a.bcd...$

$N$ rounded to two decimal places is

  • 1.00 if $0\leq X <5$
  • 1.01 if $X\geq5$

EG

$$1.006347 \to 1.01$$ $$1.005012 \to 1.01$$ $$1.004912 \to 1.00$$