Angular material localeString 的输入没有绑定

Angular material input to localeString isn't binding

我正在使用 angular material 11.2 并有一个要求,我试图将输入的字符串转换为美元。

我试过以下方法,

<input matInput formControlName="test" (onkeyup)="onKeyUpTest($event)" type="text">

onKeyUpTest(event){
var localNum = event.target.value.toLocaleString('en-US');
this.formGroup.patchValue({
'test': localNum
)}
}

这是绑定值但没有逗号。 非常感谢任何帮助。

提前致谢。

您可以使用Intl.numberFormat功能。

console.log(new Intl.NumberFormat('en-us', { style: 'currency', currency: 'USD' }).format(number));

输出:"3,456.79"

参考文献:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat