Click here to Skip to main content
15,881,938 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
i have a two variable in typescript in angular 9 like

amountvalue: number = 21.36548;
decimalplace: 3;

in html
<mat-label>{{ amountvalue | decimalplace }}

it result should be 21.365.
if the decimalplace = 2; my result should be 21.36

how to achieve this?

thanks

What I have tried:

Hi,
i have a two variable in typescript in angular 9 like

amountvalue: number = 21.36548;
decimalplace: 3;

in html
<mat-label>{{ amountvalue | decimalplace }}

it result should be 21.365.
if the decimalplace = 2; my result should be 21.36

how to achieve this?

thanks
Posted
Updated 21-Jan-21 4:31am
Comments
bbirajdar 21-Jan-21 10:30am    
Convert it to string and strip all extra digits from the .seperator ( decimal point)

1 solution

Use a "variable" to specify the precision.

Number.prototype.toFixed() - JavaScript | MDN[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900