How can I remove the decimal part from JavaScript number?

You could use… Math.trunc() (truncate fractional part, also see below) Math.floor() (round down) Math.ceil() (round up) Math.round() (round to nearest integer) …dependent on how you wanted to remove the decimal. Math.trunc() isn’t supported on all platforms yet (namely IE), but you could easily use a polyfill in the meantime. Another method of truncating the fractional … Read more

Is multiplication and division using shift operators in C actually faster?

Short answer: Not likely. Long answer: Your compiler has an optimizer in it that knows how to multiply as quickly as your target processor architecture is capable. Your best bet is to tell the compiler your intent clearly (i.e. i*2 rather than i << 1) and let it decide what the fastest assembly/machine code sequence … Read more

Which is better option to use for dividing an integer number by 2?

Use the operation that best describes what you are trying to do. If you are treating the number as a sequence of bits, use bitshift. If you are treating it as a numerical value, use division. Note that they are not exactly equivalent. They can give different results for negative integers. For example: -5 / … Read more