how to add decimal in angular reactive form control with value starting with 1 and greater

Issue

I want to add a decimal and then 0 after 1 like 1.0

<input type="number" formControlName="global_velocity_weight" />

this.form = this.fb.group({
   global_velocity_weight: new FormControl(1.0, { validators: [Validators.required] })
})

But it is not working and in the input, only 1 is shown.

Solution

you can achieve this using angular DecimalPipe inside your form template.

<form [formGroup]="myForm">
    <input 
        [value]="myForm.get('global_velocity_weight').value | number" // here you pipe the value
        formControlName="global_velocity_weight" 
    
        ...
    >
</form>

Answered By – user12163165

Answer Checked By – Jay B. (AngularFixing Admin)

Leave a Reply

Your email address will not be published.