Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Block Round Off using decimal pipe in angular 4

Using angular 4,

{{31.94 | number:'1.0-0'}} 

Output: 32

Any idea, how to block the round off. Expecting the result is 31

like image 264
Sudip Pal Avatar asked Oct 27 '25 12:10

Sudip Pal


1 Answers

You need to create your custom pipe as DecimalPipe doesn't provide any floor feature. Plus you can add your decimal pipe in it. Your Custom Pipe:

@Pipe({name: 'floor'})
export class FloorPipe implements PipeTransform {
    /**
     *
     * @param value
     * @returns {number}
     */
    transform(value: number): number {
        return Math.floor(value);
    }
}

Use in template as:

  <span>{{ yournumber | floor | your_decimal_pipe }}</span>
like image 149
Ankit Kapoor Avatar answered Oct 30 '25 02:10

Ankit Kapoor



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!