Angular – Limit decimal to two places without rounding off

Issue

I am using the decimal pipe to limit decimal number to two places:

{{amount | number:'1.2-2'}}

But unfortunately the above pipe rounds off the number. Is there any way I can limit the output to two places after decimal without rounding off the number.

Solution

I’d suggest that you write a custom pipe to do this.

The documentation is found here:

https://angular.io/guide/pipes#custom-pipes

Here is a good example how to use a pipe for formating numbers

Angular 2 – Number pipe for scientific notation numbers

Answered By – tomichel

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published