-1

I am new to angularJs. I am getting scope value from my java action as list. The price is double in database object. I need to chcek if the value is coming with decimal ex: 32.5 or not, if its 32.5 then , i need to show 32.50, if the value comes like 30.0, then it will display 30 only.

Can anyone please suggest. thanks

user1894465
  • 67
  • 1
  • 1
  • 8
  • Please add details about "my java action as list"... A bit of code wouldn't hurt, either... :-) – MarcoS May 02 '14 at 12:39
  • 1
    AngularJS is just javascript at its core. You can use any javascript functions you want. I'm not sure I understand your rounding requirements but take a look at this question: http://stackoverflow.com/questions/11832914/round-to-at-most-2-decimal-places-in-javascript – drew_w May 02 '14 at 12:39
  • At first I thought like drew_w, but I think the question is not about manipulating the number if it is an integer or not, but just to present it. In that case it is an angular question and I would use a filter to present it as a string. https://docs.angularjs.org/guide/filter – haimlit May 02 '14 at 12:58
  • yes, this is an angular question, i need to resolve it in angular way, can you pls tell me how can i filter it? – user1894465 May 02 '14 at 13:06
  • Try to write a filter that receives a number and outputs it as a nice string like you describe. Then in your template, use the variable that has the number and pass it to the filter. If you have any trouble, post a plunkr of what you have so far and we'll continue from there. – haimlit May 02 '14 at 14:04
  • i have added some code, pls suggest the right way. thanks – user1894465 May 02 '14 at 14:23

1 Answers1

1

Try using the number filter.

Number Filter

Shivaraj
  • 613
  • 3
  • 10