Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 角度5从API响应中省略1.0中的.0_Javascript_Angular_Typescript_Api_Httpresponse - Fatal编程技术网

Javascript 角度5从API响应中省略1.0中的.0

Javascript 角度5从API响应中省略1.0中的.0,javascript,angular,typescript,api,httpresponse,Javascript,Angular,Typescript,Api,Httpresponse,在Angular 5中,我得到的API响应为1.0。但是当填充到html字段时,它显示为1 在chrome开发工具中,在网络选项卡->响应下,它显示为1.0,但在网络选项卡->预览下,它显示为1 我试着将响应映射到一个角度的模型上,但都不起作用 response is : { amount: 1.0, quantity : 3.0, id: "20184563251", } this.result = reportRespo

在Angular 5中,我得到的API响应为1.0。但是当填充到html字段时,它显示为1

在chrome开发工具中,在网络选项卡->响应下,它显示为1.0,但在网络选项卡->预览下,它显示为1

我试着将响应映射到一个角度的模型上,但都不起作用

 response is : 
    {
        amount: 1.0,
        quantity : 3.0,
        id: "20184563251",
    }


this.result = reportResponse.body;
this.cartForm.patchValue(
    {
        'inputTextField': this.result.amount, // While patching only 1 is patched
     });
尝试。它将返回一个字符串

this.rateData.amount.toFixed(1)
尝试。它将返回一个字符串

this.rateData.amount.toFixed(1)

把它当作数字,最好先把它转换成字符串

this.result = reportResponse.body;
this.cartForm.patchValue(
    {
        'inputTextField': String( this.rateData.amount), // convert it to string
     });

把它当作数字,最好先把它转换成字符串

this.result = reportResponse.body;
this.cartForm.patchValue(
    {
        'inputTextField': String( this.rateData.amount), // convert it to string
     });

如果我使用toFixed1,如果金额由1个以上的小数组成,则只显示一个数字。例:2.46显示为2.5。但是我们想显示为2.46,在通过toFixed1之前,只需输入一个条件如果我使用toFixed1,如果数量包含超过1个小数点,则只显示一个数字。例:2.46显示为2.5。但我们想显示为2.46,在通过toFixed之前,只需放置一个条件