Vinod
Vinod

Reputation: 57

how to remove decimal part from the data in angular js

While im removing the decimal , its getting round off . but i want to remove decimal point only. while my data is 3.7 , im getting 4.

sample data 3.7
Exp op 3

code

 <li class="temp">Temperature  <span> {{Temperature.Ch1Temp | number:0}} </span></li>

Upvotes: 0

Views: 630

Answers (2)

Marc
Marc

Reputation: 11613

Why not Math.floor()?

<li class="temp">Temperature  <span>{{ Math.floor(Temperature.Ch1Temp) }}</span></li>

Just keep in mind how that will also impact negative numbers.

Angular JS

Furthermore, as mentioned in the comments, you will need to bind the Math library into your controller, as described in this answer, and excerpted as follows:

$scope.Math = window.Math;

AngularJS Example HERE.

Modern Angular

If you're using a modern Angular, you'll need to explicitly assign the Math library in your component's Typescript, like this:

export class AppComponent {
  number = 3.7;
  Math = Math; //explicitly bind the Math library so it's usable in template
}

There's a working Stackblitz example HERE:

Upvotes: 1

baggiedom
baggiedom

Reputation: 1

You could convert the number into an int using parseInt inside a js function

Upvotes: 0

Related Questions