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

Nisarg Pujara
  • 43
  • 1
  • 1
  • 10
  • 1
    He means convert inside angularjs expression. So it duplicate with this: http://stackoverflow.com/questions/26293769/how-to-parseint-in-angular-js – Tai Huynh Mar 20 '15 at 09: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. – Zoltán Dec 03 '15 at 16:52

2 Answers2

16
{{val | number:0}}

it will convert val into integer

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

Jameel Grand
  • 2,294
  • 16
  • 32
  • 1
    This should be the accepted answer, because it's much cleaner and does not change the value, only its format – kaiser Dec 11 '18 at 15:57
3

Just use floor():

Math.floor(document.size/1024)
xlecoustillier
  • 16,183
  • 14
  • 60
  • 85