0

I am using ngx-mask like this:

<input type="text" class="form-control"
                                       id="price" 
                                       name="price" 
                                       [(ngModel)]="product.maskPrice" 
                                      
                                        mask="separator.2" 
                                       thousandSeparator="." 
                                       >

So I have to transform this input to number, like: 1234,56 to 1234.56, because my endpoint excepts a number type for the price.

Here is my code:

product.price = +product.maskPrice!.replace(",",'.');

How is the best way to do this?

My solution use this interface to keep mask and number price information:

export interface Product {
    id ?: number;
    name ?: string;
    
    price ?: number;
    maskPrice ?: string;
    
    newProduct ?: boolean;
}

Any suggestion to improve this code? Thanks!

0 Answers0