Difference between Math. floor() and Math. round() andrey вторник, 27 мая 2014 г. No Comment

Syntax 
 Math.floor(x) , Math.round(x)

Definition

  • Math.floor(x) and Math.round(x)  expects floating number as parameter.
  • Math.floor(x) 
    • The floor() method rounds a number DOWNWARDS to the nearest integer, and returns the result.
    • If the passed argument is an integer, the value will not be rounded.
  • Math.round(x) 
    • The round() method rounds a number to the nearest integer.
Main Difference 

  • Math.floor(x)  
    • If the parameter is 3.51, it will be rounded DOWNWARDS (out put 3).
  • Math.round(x) 
    • If the parameter is 3.49, it will be rounded DOWNWARDS (out put 3).
    • If the parameter is 3.50, it will be rounded UPWARDS (out put 4).
DEMO
Have any doubt, feel free to comment here!

Syntax 
 Math.floor(x) , Math.round(x)

Definition

  • Math.floor(x) and Math.round(x)  expects floating number as parameter.
  • Math.floor(x) 
    • The floor() method rounds a number DOWNWARDS to the nearest integer, and returns the result.
    • If the passed argument is an integer, the value will not be rounded.
  • Math.round(x) 
    • The round() method rounds a number to the nearest integer.
Main Difference 

  • Math.floor(x)  
    • If the parameter is 3.51, it will be rounded DOWNWARDS (out put 3).
  • Math.round(x) 
    • If the parameter is 3.49, it will be rounded DOWNWARDS (out put 3).
    • If the parameter is 3.50, it will be rounded UPWARDS (out put 4).
DEMO
Have any doubt, feel free to comment here!

by Jillur Rahman

Jillur Rahman is a Web designers. He enjoys to make blogger templates. He always try to make modern and 3D looking Templates. You can by his templates from Themeforest.

Follow him @ Twitter | Facebook | Google Plus

No Comment