1

I have a class that I need an actual decimal field

export myclass {
deposit: number;
}

however when i convert my web api class to this typescript class my decimal amounts that should look like this 1.10 look like this 1.1 when the object is converted.

I need that zero to stay put. How can I do this in typescript?

Terrance Jackson
  • 606
  • 3
  • 13
  • 40

1 Answers1

3

A number type is always going to remove trailing zeroes in the decimals place. To have 1.10 you would need to represent it as a string.

You can use toFixed to specify the number of decimal places you want, but the output is a string.

const num = 1.10;

console.log(num);
console.log(num.toFixed(2));
stjns
  • 1,420
  • 13
  • 16