ccdavies
ccdavies

Reputation: 1606

Ensuring number has 2 numbers after decimal

I am using the following to calculate:

Math.round(parseInt(optionPrice * 100, 10) * eurRate) / 100;

Which in one instance returns:

68.4

How can I ensure the number is always returned like so:

68.40

Upvotes: 0

Views: 35

Answers (1)

Varun
Varun

Reputation: 1946

Use javascripts .toFixed() method.

In you case, it would be toFixed(2). Where the number in bracket is the number of positions after decimal.

Eg:(Math.round(parseInt(optionPrice * 100, 10) * eurRate) / 100).toFixed(2);

Upvotes: 4

Related Questions