1

I have following code snippet :

<span ng-if="document.size<500" >
    0
</span> 
<span ng-if="document.size >=500 && document.size < 1048576" >
    {{document.size/1024}}
</span> 
<span ng-if="document.size >=1048576" >
    {{document.size/1048576}}
</span>

i got document size in byte and then i convert it into KB and MB. but it gives value in double. how can i convert it into int in angular js? can i convert it in int expression directly? Thanks in advance

2
  • 1
    He means convert inside angularjs expression. So it duplicate with this: stackoverflow.com/questions/26293769/… Commented Mar 20, 2015 at 9:12
  • 1
    The answer by Janeel Grand gives an exact, concise answer (hot to do it in angular), arguably better than the answers linked to by @TaiHuynh, and certainly better than the more general question which this question is marked a duplicate of. Commented Dec 3, 2015 at 16:52

2 Answers 2

16
{{val | number:0}}

it will convert val into integer

go through with this link docs.angularjs.org/api/ng/filter/number

Sign up to request clarification or add additional context in comments.

1 Comment

This should be the accepted answer, because it's much cleaner and does not change the value, only its format
3

Just use floor():

Math.floor(document.size/1024)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.