Javascript – Casting to integer on arithmetic division…

 


crosspost from http://rex.la/blogs/work/


Been rushing on my working project and coding a lot Ajax using Ajax.net lately. Had a lot of  re-practice back to javascript. here is a quick pick of one of them.


As Javascript been a weak-typed language, sometimes it’s not able to cast a variable from one type to another. as in arithmetic division, if one wants to output an integer instead of a double or else, here is a way learned from this article that’s useful:


a = ( b / c ) | 0


by using a bitwise OR operation to cast a float / double back to an integer, to have a way casting some numeric values back to desired form.


also there is a nice Javascript language reference I dig a lot during this coding. thanks for the help!


Technorati Tags: asp.net , programming , javascript 


 

2 thoughts on “Javascript – Casting to integer on arithmetic division…”

  1. Pretty interesting blog you’ve got here. Thanks for it. I like such topics and anything connected to this matter. I definitely want to read more on that blog soon.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>