How to parse float with two decimal places in javascript?

前端 未结 16 1719
春和景丽
春和景丽 2020-11-27 08:55

I have the following code. I would like to have it such that if price_result equals an integer, let\'s say 10, then I would like to add two decimal places. So 10 would be 10

16条回答
  •  旧巷少年郎
    2020-11-27 09:51

    Solution for FormArray controllers 
    

    Initialize FormArray form Builder

      formInitilize() {
        this.Form = this._formBuilder.group({
          formArray: this._formBuilder.array([this.createForm()])
        });
      }
    

    Create Form

      createForm() {
        return (this.Form = this._formBuilder.group({
          convertodecimal: ['']
        }));
      }
    

    Set Form Values into Form Controller

      setFormvalues() {
        this.Form.setControl('formArray', this._formBuilder.array([]));
        const control = this.resourceBalanceForm.controls['formArray'];
        this.ListArrayValues.forEach((x) => {
          control.push(this.buildForm(x));
        });
      }
    
      private buildForm(x): FormGroup {
        const bindvalues= this._formBuilder.group({
          convertodecimal: x.ArrayCollection1? parseFloat(x.ArrayCollection1[0].name).toFixed(2) : '' // Option for array collection
    // convertodecimal: x.number.toFixed(2)    --- option for two decimal value 
        });
    
        return bindvalues;
      }
    

提交回复
热议问题