0

This is my html code:

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

The problem is that I want to show the number in this way:

10.00
100.10
100.88
199.99

( I want a number with unlimited integer part and at least two digits)

With my code if there is this numbero 100.10 it show me 100.1. Anyone can help me?

Doflamingo19
  • 1,591
  • 4
  • 12
  • 32

4 Answers4

2

You can use parseFloat('151.8').toFixed(2);

Suresh Kumar Ariya
  • 9,516
  • 1
  • 18
  • 27
0

you should add an prop to the input tag like this

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

that will be work.good luck!

0

Assuming you have :

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

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

if you try using DecimalPipe of angular you'll get it:

{{home |  number:'1.1-1'}}
SeleM
  • 9,310
  • 5
  • 32
  • 51
0

You can convert your number to String which will trim the trailing zeros of your number

make the following changes in your .html file

<input type="number" class="form-control" [(ngModel)]="home"  name="home" >
<p>{{home.toString()}}</p> <!-- converting into string -->
Sarthak Aggarwal
  • 2,284
  • 1
  • 8
  • 12