Block Round Off using decimal pipe in angular 4

Clash Royale CLAN TAG#URR8PPP
Block Round Off using decimal pipe in angular 4
Using angular 4,
number:'1.0-0'
Output: 32
Any idea, how to block the round off. Expecting the result is 31
2 Answers
2
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 </span>
You can use multiple pipes then yournumber
– Ankit Kapoor
Nov 21 '17 at 15:30
Yes, I can write a custom pipe to do the work (floor value, comma formatted etc.) but just wanted to confirm if angular decimal pipe already have the config or not.
– Sudip Pal
Nov 21 '17 at 15:32
No, they don't.
– Ankit Kapoor
Nov 21 '17 at 15:33
If you find your solution from this you can mark it correct :)
– Ankit Kapoor
Nov 21 '17 at 15:37
your.component.ts
import Component, Pipe, PipeTransform from '@angular/core';
@Pipe(name: 'DecimalPipe')
export class NumNotRoundPipe implements PipeTransform
transform(value: number): number
var num1 = Math.floor(value * 100) / 100;
return num1;
your.module.ts
import NumNotRoundPipe from './your.component'
@NgModule(
imports: [
],
declarations: [
NumNotRoundPipe
],
entryComponents: [
],
providers: [
],
schemas: [CUSTOM_ELEMENTS_SCHEMA]
)
your.component.html
<span>yourNumber </span>
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
It will just floor the value, but I will be missing the comma (whatever decimal pipe doing) in case of using 1999.99, it will not gives us 1,999
– Sudip Pal
Nov 21 '17 at 15:28