Angular 如何避免输入类型编号删除;0“;最后一个数字

Angular 如何避免输入类型编号删除;0“;最后一个数字,angular,angular6,Angular,Angular6,这是我的html代码: <input type="number" class="form-control" [(ngModel)]="home" name="home" > (我想要一个不限整数部分且至少两位数的数字) 用我的代码,如果有这个数字100.10,它会显示100.1。有人能帮我吗?你应该像这样在输入标签中添加一个道具 <input type="number" min="0" max="100" step="0.01"/> 那会有用的。祝你好运 您应

这是我的html代码:

 <input type="number" class="form-control" [(ngModel)]="home"  name="home" >
(我想要一个不限整数部分且至少两位数的数字)


用我的代码,如果有这个数字100.10,它会显示100.1。有人能帮我吗?

你应该像这样在输入标签中添加一个道具

<input type="number" min="0" max="100" step="0.01"/>


那会有用的。祝你好运

您应该向输入标记添加一个道具,如下所示

<input type="number" min="0" max="100" step="0.01"/>

那会有用的。祝你好运

假设您有:

<input type="number" class="form-control" [(ngModel)]="home"  name="home" >

<p>{{home}}</p>
假设你有:

<input type="number" class="form-control" [(ngModel)]="home"  name="home" >

<p>{{home}}</p>

您可以将数字转换为字符串,该字符串将修剪数字的尾随零

.html文件中进行以下更改

<input type="number" class="form-control" [(ngModel)]="home"  name="home" >
<p>{{home.toString()}}</p> <!-- converting into string -->

{{home.toString()}}


您可以将数字转换为字符串,该字符串将修剪数字的尾随零

.html文件中进行以下更改

<input type="number" class="form-control" [(ngModel)]="home"  name="home" >
<p>{{home.toString()}}</p> <!-- converting into string -->

{{home.toString()}}


您可以使用parseFloat('151.8')。toFixed(2)

可以使用parseFloat('151.8').toFixed(2)

您可以使用ngx mask ref:您可以尝试将其转换为字符串,如@SarthakAggarwal所示,但在我如何使用.ts文件中的变量进行绑定之后,因为ts组件中的this.home是number@Doflamingo19在.component.html中,使用
{{home.toString()}}
您可以使用ngx mask ref:您可以尝试将其转换为字符串,如@SarthakAggarwal所示,但在我如何使用.ts文件中的变量进行绑定之后,因为ts组件中的this.home是number@Doflamingo19在.component.html中,使用
{{home.toString()}}
Selem我只是尝试使用thuis解决方案,但当修改代码时,它不会在输入类型编号中显示编号!我需要在输入类型编号中显示编号,而不是在

标记中。您的代码缺失,请添加修改部分,因此@Doflamingo19Selem我只是尝试使用thuis解决方案,但在修改代码时,它不会在输入类型编号中显示编号!我需要在输入类型编号中显示编号,而不是在标记中显示编号。您的代码缺失,请添加修改部分,因此@Doflamingo19