I really did not understand how the type assignment system works for variables in typescript. Can anyone help me why this does not work. Thank you
valorParcela:number;
totalCost:number;
VendaProdutoVendaNParcelas: number;
this.valorParcela = Number( this.totalCost / this.VendaProdutoVendaNParcelas).toFixed(2);
I expected a simple parseFloat
toFixed
returns a string
which you are assigning to a variable which should be number
. You need another pair of ()
to convert the result of toFixed
back to number
this.valorParcela = Number(( this.totalCost / this.VendaProdutoVendaNParcelas).toFixed(2));
Or you can use the unary +
trick to perform number conversion:
this.valorParcela = +(this.totalCost / this.VendaProdutoVendaNParcelas).toFixed(2);
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments