-2

I have a number with decimal points like --> 1.33

I want to convert the this value that instead a dot a comma is shown.

I tried that with a custom pipe but that didn´t work.

{{getMyValue() | number:'1.2-2' | commaConvert}}
import { Pipe, PipeTransform } from "@angular/core";

@Pipe({name: 'commaConvert'})
export class CommaConvertPipe implements PipeTransform {
    transform(value: number) {
        return value+"".replace(".", ",")
    }
}

I have also tried to use only the commaConvert pipe.

JuNe
  • 1,911
  • 9
  • 28
  • 1
    Could you clarify *"doesn't work"*? Also note that the output of DecimalPipe#transform and therefore the input of CommaConvertPipe#transform is string, not number. – jonrsharpe Oct 02 '19 at 06:45
  • You were right. The problem was that the value from the DecimalPipe was a string and not a number. – JuNe Oct 02 '19 at 06:48
  • 3
    `value+"".replace(".", ",")` means you only replace in `""`. –  Oct 02 '19 at 06:49

1 Answers1

-1

Please, edit in transform return

return value.toString().replace(".", ",")
Phat Huynh
  • 772
  • 5
  • 16