26

I currently use this pipe {{ product.productPrice | number:'.2-2' }}

And result is 1,000,000.00 but I want to remove the .00 How do you do that?

Char
  • 2,073
  • 8
  • 28
  • 45
  • @Vega: The edits were only on the title (from the OP, more descriptive) and from me (removed an inadequate tag), I don't think anything substantial from the question has been changed. – Pac0 Aug 30 '17 at 08:49

1 Answers1

61

Use this :

  {{product.productPrice | number: '1.0-0'}}

1.0-0 means: at least one digit before decimal point, 0 digits after decimal point.

The general format is:

{minIntegerDigits}.{minFractionDigits}-{maxFractionDigits}

minIntegerDigits: The minimum number of integer digits before the decimal point. Default is 1.
minFractionDigits: The minimum number of digits after the decimal point. Default is 0. maxFractionDigits: The maximum number of digits after the decimal point. Default is 3.

https://angular.io/api/common/DecimalPipe

Vega
  • 27,856
  • 27
  • 95
  • 103
  • what if I have 10 (100.10) after digit and don't want to remove it but want to remove if it is 100.00? do I need to handle it separately? – Pratap A.K Feb 26 '18 at 13:38
  • is it possible just get one digit before decimal point without rounding up? I mean `-1.75` should be `1`, not `2`? – StepUp Aug 23 '18 at 07:06
  • @StepUp, Angular decimal pipe rounds down and for the negative numbers that means up as a an absolute number. You can use just Math.trunc() before applying the pipe? Something like this: https://stackblitz.com/edit/angular-fbongy – Vega Aug 23 '18 at 07:13
  • @Vega I am sorry, however I cannot see your code. Could you show, please, your code? I see just a page with code, however without `Math.trunc()`. – StepUp Aug 23 '18 at 07:25
  • I've seen `Main.ts` and `polyfill.ts` files, however there is no `Math.trunc()`. May be this file is not saved. Could you post here your code? – StepUp Aug 23 '18 at 07:30
  • @Vega this {{ 3000 | number: '1.0-0' }} return 3.000, why? – juanjinario Jun 09 '21 at 16:09
  • @juanjinario, 3.000 is just formatted for thousands, it is not a decimal number. What are you looking to achieve? – Vega Jun 09 '21 at 16:13