From this lesson, we learn about JS static object: ```Math```. It mainly helps us to carry out mathematical calculations. It has a lot of properties and methods. Some of the properties and methods we rarely used. So we only learn some common methods.

The properties of the Math object are some constants, such as PI, on behalf of the approximate value of pi. The usage is ```Math.PI```. I will no longer introduce one by one, please refer to the manual:
      
  - [Math Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math)

In this lesson we learn three methods to turn a number into an integer: ```round()```, ```ceil()``` and ```floor()```. 

Their definitions and detailed information:

- [Math.round()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/round)
- [Math.ceil()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/ceil)
- [Math.floor()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/floor)

First of all, we have to understand the first thing, all the methods of the Math object are static methods. It means that you need to use the Math method like this: ```Math.round(1.23)```. Not like this: ```(1.23).round()```.

Here we use some examples to understand their usage:

We can see, ```ceil()``` always rounding up to get a large integer; ```floor()``` always rounding down to get a small integer; ```round()``` according to the fractional part and round it to integer.

When the parameter is negative, they still works:
It should be noted that they are not working on the fractional part. If you want to keep two decimal places or otherwise, you should use [Methods of Number object--toFixed(), toExponential() and toPrecision()](http://www.codewars.com/kata/57256064856584bc47000611), or use the following techniques:
In the example above, we first multiply the number by 100, and then round it. the final result is to retain two decimal places.

Ok, lesson is over. let's us do some task.

## Task

Coding in function ```roundIt```. function accept 1 parameter ```n```. It's a number with a decimal point. Please use different methods based on the location of the decimal point, turn the number into an integer.

If the decimal point is on the left side of the number (that is, the count of digits on the left of the decimal point is less than that on the right), Using ```ceil()``` method.
```
roundIt(3.45) should return 4
```
If the decimal point is on the right side of the number (that is, the count of digits on the left of the decimal point is more than that on the right), Using ```floor()``` method.
```
roundIt(34.5) should return 34
```
If the decimal point is on the middle of the number (that is, the count of digits  on the left of the decimal point is equals that on the right), Using ```round()``` method.
```
roundIt(34.56) should return 35
```

## [Series](http://github.com/myjinxin2015/Katas-list-of-Training-JS-series)

( ↑↑↑ Click the link above can get my newest kata list, Please add it to your favorites)

 - [#1: create your first JS function helloWorld](http://www.codewars.com/kata/571ec274b1c8d4a61c0000c8)
 - [#2: Basic data types--Number](http://www.codewars.com/kata/571edd157e8954bab500032d)
 - [#3:  Basic data types--String](http://www.codewars.com/kata/571edea4b625edcb51000d8e)
 - [#4:  Basic data types--Array](http://www.codewars.com/kata/571effabb625ed9b0600107a)
 - [#5:  Basic data types--Object](http://www.codewars.com/kata/571f1eb77e8954a812000837)
 - [#6:  Basic data types--Boolean and conditional statements if..else](http://www.codewars.com/kata/571f832f07363d295d001ba8)
 - [#7:  if..else and ternary operator](http://www.codewars.com/kata/57202aefe8d6c514300001fd)
 - [#8: Conditional statement--switch](http://www.codewars.com/kata/572059afc2f4612825000d8a)
 - [#9: loop statement --while and do..while](http://www.codewars.com/kata/57216d4bcdd71175d6000560)
 - [#10: loop statement --for](http://www.codewars.com/kata/5721a78c283129e416000999)
 - [#11: loop statement --break,continue](http://www.codewars.com/kata/5721c189cdd71194c1000b9b)
 - [#12: loop statement --for..in and for..of](http://www.codewars.com/kata/5722b3f0bd5583cf44001000)
 - [#13: Number object and  its properties](http://www.codewars.com/kata/5722fd3ab7162a3a4500031f)
 - [#14: Methods of Number object--toString() and toLocaleString()](http://www.codewars.com/kata/57238ceaef9008adc7000603)
 - [#15: Methods of Number object--toFixed(), toExponential() and toPrecision()](http://www.codewars.com/kata/57256064856584bc47000611)
 - [#16: Methods of String object--slice(), substring() and substr()](http://www.codewars.com/kata/57274562c8dcebe77e001012)
 - [#17: Methods of String object--indexOf(), lastIndexOf() and search()](http://www.codewars.com/kata/57277a31e5e51450a4000010)
 - [#18: Methods of String object--concat() split() and its good friend join()](http://www.codewars.com/kata/57280481e8118511f7000ffa)
 - [#19: Methods of String object--toUpperCase() toLowerCase() and replace()](http://www.codewars.com/kata/5728203b7fc662a4c4000ef3)
 - [#20: Methods of String object--charAt() charCodeAt() and fromCharCode()](http://www.codewars.com/kata/57284d23e81185ae6200162a)
 - [#21: Methods of String object--trim() and the string template](http://www.codewars.com/kata/5729b103dd8bac11a900119e)
 - [#22: Unlock new skills--Arrow function,spread operator and deconstruction](http://www.codewars.com/kata/572ab0cfa3af384df7000ff8)
 - [#23: methods of arrayObject---push(), pop(), shift() and unshift()](http://www.codewars.com/kata/572af273a3af3836660014a1)
 - [#24: methods of arrayObject---splice() and slice()](http://www.codewars.com/kata/572cb264362806af46000793)
 - [#25: methods of arrayObject---reverse() and sort()](http://www.codewars.com/kata/572df796914b5ba27c000c90)
 - [#26: methods of arrayObject---map()](http://www.codewars.com/kata/572fdeb4380bb703fc00002c)
 - [#27: methods of arrayObject---filter()](http://www.codewars.com/kata/573023c81add650b84000429)
 - [#28: methods of arrayObject---every() and some()](http://www.codewars.com/kata/57308546bd9f0987c2000d07)
 - [#29: methods of arrayObject---concat() and join()](http://www.codewars.com/kata/5731861d05d14d6f50000626)
 - [#30: methods of arrayObject---reduce() and reduceRight()](http://www.codewars.com/kata/573156709a231dcec9000ee8)
 - [#31: methods of arrayObject---isArray() indexOf() and toString()](http://www.codewars.com/kata/5732b0351eb838d03300101d)
 - [#32: methods of Math---round() ceil() and floor()](http://www.codewars.com/kata/5732d3c9791aafb0e4001236)
 - [#33: methods of Math---max() min() and abs()](http://www.codewars.com/kata/5733d6c2d780e20173000baa)
 - [#34: methods of Math---pow() sqrt() and cbrt()](http://www.codewars.com/kata/5733f948d780e27df6000e33)
 - [#35: methods of Math---log() and its family](http://www.codewars.com/kata/57353de879ccaeb9f8000564)
 - [#36: methods of Math---kata author's lover:random()](http://www.codewars.com/kata/5735956413c2054a680009ec)
 - [#37: Unlock new weapon---RegExp Object](http://www.codewars.com/kata/5735e39313c205fe39001173)
 - [#38: Regular Expression--"^","$", "." and test()](http://www.codewars.com/kata/573975d3ac3eec695b0013e0)
 - [#39: Regular Expression--"?", "*", "+" and "{}"](http://www.codewars.com/kata/573bca07dffc1aa693000139)
 - [#40: Regular Expression--"|", "[]" and "()"](http://www.codewars.com/kata/573d11c48b97c0ad970002d4)
 - [#41: Regular Expression--"\"](http://www.codewars.com/kata/573e6831e3201f6a9b000971)
 - [#42: Regular Expression--(?:), (?=) and (?!)](http://www.codewars.com/kata/573fb9223f9793e485000453)

Source: codewars | Difficulty: EASY
Tags: Fundamentals

Starter code: def round_it(n):
	

Solutions:
from math import ceil

def round_it(n):
	(left, right) = (len(part) for part in str(n).split('.'))
	return ceil(n) if left < right else int(n) if left > right else round(n)


from math import floor, ceil

def round_it(n):
	(l, r) = [len(x) for x in str(n).split('.')]
	if r > l:
		return ceil(n)
	elif r < l:
		return floor(n)
	else:
		return round(n)


def round_it(f):
	(n, d) = str(f).split('.')
	return round(f) if len(n) == len(d) else int(n) + (len(n) < len(d))


from math import ceil

def round_it(n):
	(a, b) = map(len, str(n).split('.'))
	if a > b:
		return int(n)
	if b > a:
		return ceil(n)
	return round(n)


import math

def round_it(n):
	s = str(n)
	afterDecimal = len(s) - s.index('.') - 1
	beforeDecimal = len(s) - afterDecimal - 1
	if afterDecimal > beforeDecimal:
		return math.ceil(n)
	elif afterDecimal < beforeDecimal:
		return math.floor(n)
	else:
		return round(n)


def round_it(n):
	(a, b) = map(len, str(n).split('.'))
	return round(n) if a == b else int(n) + (a < b)


def round_it(n):
	(a, b) = list(map(len, str(n).split('.')))
	return (int(n) + 1, int(n), round(n))[(a >= b) + (a == b)]


import math

def round_it(a):
	b = list(map(len, str(a).split('.')))
	return (math.ceil(a), int(a), round(a))[(b[0] >= b[1]) + (b[0] == b[1])]


import math

def round_it(n):
	(left, right) = str(n).split('.')
	if len(left) < len(right):
		result = math.ceil(n)
	elif len(left) > len(right):
		result = math.floor(n)
	else:
		result = round(n)
	return result


def round_it(n):
	(left, right) = map(len, str(n).split('.'))
	return int(n) + 1 if left < right else int(n) if left > right else round(n)


import math

def round_it(num):
	(left, right) = str(num).split('.')
	if len(left) < len(right):
		return math.ceil(num)
	if len(left) > len(right):
		return math.floor(num)
	if len(left) == len(right):
		return round(num)


from math import ceil, floor

def round_it(n):
	t = str(n).split('.')
	t = [len(x) for x in t]
	return ceil(n) if t[0] < t[1] else floor(n) if t[0] > t[1] else round(n)


round_it = lambda n, m=__import__('math'), f=lambda x, y: (x < y) + (x <= y): [m.floor, round, m.ceil][f(*[len(e) for e in str(n).split('.')])](n)


def round_it(n):
	(l, r) = [len(i) for i in str(n).split('.')]
	if l < r:
		return int(n + 0.9)
	elif l > r:
		return int(n - 0.1)
	return round(n, 0)


from math import ceil as c, floor as f

def round_it(n):
	(k, l) = map(len, str(n).split('.'))
	return eval('[[c,f][k>l],round][k==l](n)')


from math import ceil, floor

def round_it(n):
	(a, b) = map(len, str(n).split('.'))
	return (ceil, floor, round)[(a > b) + (a == b) * 2](n)


def round_it(n):
	return int(n // 1) if len(str(n).split('.')[0]) > len(str(n).split('.')[1]) else int(n // 1 + 1) if len(str(n).split('.')[0]) < len(str(n).split('.')[1]) else round([round(n, x) for x in list(range(len(str(n).split('.')[1]), 0, -1))][-1])


from math import ceil, floor

def round_it(n):
	(l, r) = map(len, str(abs(n)).split('.'))
	return (round, ceil, floor)[(l < r) - (l > r)](n)


from math import ceil, floor

def round_it(n):
	case = 2 * str(n).index('.') - len(str(n)) + 1
	return (round, ceil, floor)[(case < 0) - (case > 0)](n)


def round_it(n):
	from math import ceil, floor
	p = str(n).find('.') / (len(str(n)) - 1)
	return ceil(n) if p < 0.5 else floor(n) if p > 0.5 else round(n)


def round_it(n):
	(l, r) = map(len, str(n).split('.'))
	return [int(n + 1), int(n), int(n + 0.5)][[l < r, l > r, r == l].index(True)]


def round_it(n):
	dec_pos = str(n).find('.')
	num_before = dec_pos
	num_after = len(str(n)) - dec_pos - 1
	if num_before < num_after:
		return int(n + 1)
	elif num_before > num_after:
		return int(n)
	elif num_before == num_after:
		return round(n)
	return


from math import floor, ceil

def round_it(n: float) -> int:
	(_integer_len, _fractal_len) = list(map(len, str(n).split('.')))
	round_f = {_integer_len < _fractal_len: ceil, _integer_len > _fractal_len: floor, _integer_len == _fractal_len: round}
	return round_f[True](n)


import math

def round_it(n):
	position = str(n).index('.')
	length = len(str(n)) - 1
	if position < length / 2:
		return math.ceil(n)
	elif position > length / 2:
		return math.floor(n)
	else:
		return round(n)


from math import ceil, floor

def round_it(n):
	return ceil(n) if len(str(n).split('.')[0]) < len(str(n).split('.')[1]) else floor(n) if len(str(n).split('.')[0]) > len(str(n).split('.')[1]) else round(n)


import math

def round_it(n):
	s = str(n).split('.')
	print(s[0], s[1])
	return math.floor(n) if len(s[0]) > len(s[1]) else math.ceil(n) if len(s[0]) < len(s[1]) else round(n)


from math import ceil

def round_it(n):
	left = len(str(n).split('.')[0])
	right = len(str(n).split('.')[1])
	return int(n) if left > right else ceil(n) if left < right else round(n)


import math

def round_it(n):
	print(n)
	count_whole = len(str(round(n)))
	count = len(str(n))
	if count - 1 - count_whole == count_whole:
		return round(n)
	elif count - 1 - count_whole > count_whole:
		return math.ceil(n)
	else:
		return math.floor(n)


from math import floor
from math import ceil

def round_it(n):
	a = list(map(len, str(n).split('.')))
	if a[0] == a[1]:
		return round(n)
	elif a[0] > a[1]:
		return floor(n)
	elif a[0] < a[1]:
		return ceil(n)


from math import floor, ceil

def round_it(n):
	(a, b) = str(n).split('.')
	if len(a) > len(b):
		return floor(n)
	if len(a) < len(b):
		return ceil(n)
	return round(n)


from math import floor, ceil

def round_it(n):
	(left, right) = str(n).split('.')
	if len(left) == len(right):
		return round(n)
	if len(left) > len(right):
		return floor(n)
	if len(left) < len(right):
		return ceil(n)


import math

def round_it(n):
	sl = str(n).split('.')
	l0 = len(sl[0])
	l1 = len(sl[1])
	if l0 < l1:
		return math.ceil(n)
	elif l0 > l1:
		return math.floor(n)
	else:
		return round(n)


import math

def round_it(n):
	lst = list(str(n))
	i = lst.index('.')
	print(lst)
	if len(lst[0:i]) > len(lst[i:-1]):
		return math.floor(n)
	elif len(lst[0:i]) < len(lst[i:-1]):
		return math.ceil(n)
	else:
		return round(n)


import math

def round_it(n):
	mat = str(n).split('.')
	if len(mat[0]) > len(mat[1]):
		return math.floor(n)
	elif len(mat[0]) < len(mat[1]):
		return math.ceil(n)
	elif len(mat[0]) == len(mat[1]):
		return round(n)


import math

def round_it(n):
	l = str(n).split('.')
	x = len(l[0])
	y = len(l[1])
	return math.ceil(n) if x < y else math.floor(n) if x > y else round(n)


import math

def round_it(n):
	f = len
	k = str(n)
	k = k.split('.')
	(a, b) = k
	if f(a) < f(b):
		return math.ceil(n)
	elif f(a) > f(b):
		return math.floor(n)
	else:
		return round(n)


import math

def round_it(n):
	d_split = str(n).split('.')
	if len(d_split[0]) > len(d_split[1]):
		return math.floor(n)
	elif len(d_split[1]) > len(d_split[0]):
		return math.ceil(n)
	else:
		return round(n)


from math import ceil

def round_it(n):
	x = str(n).split('.')
	if len(x[0]) < len(x[1]):
		return ceil(n)
	if len(x[0]) > len(x[1]):
		return int(n)
	return round(n, 0)


import math

def round_it(n):
	if (len(str(n)) + 1) / 2 > str(n).find('.') + 1:
		return math.ceil(n)
	elif (len(str(n)) + 1) / 2 == str(n).find('.') + 1:
		return round(n)
	elif (len(str(n)) + 1) / 2 < str(n).find('.') + 1:
		return math.floor(n)


import numpy as np

def round_it(n):
	return np.ceil(n) if len(str(n).split('.')[0]) < len(str(n).split('.')[1]) else np.floor(n) if len(str(n).split('.')[0]) > len(str(n).split('.')[1]) else np.round(n)


from math import ceil, floor

def round_it(n):
	s = str(n)
	if s.index('.') * 2 < len(s) - 1:
		return ceil(n)
	elif s.index('.') * 2 > len(s) - 1:
		return floor(n)
	else:
		return round(n)


def round_it(n):
	import math
	tmp = str(n).index('.')
	bef_dot = tmp
	after_dot = len(str(n)) - tmp - 1
	if bef_dot < after_dot:
		return math.ceil(n)
	if bef_dot > after_dot:
		return math.floor(n)
	if bef_dot == after_dot:
		return round(n)


from math import floor, ceil

def round_it(n):
	sn = str(n)
	i = sn.index('.')
	if len(sn) % 2 and i == len(sn) // 2:
		return round(n)
	elif i < len(sn) // 2:
		return ceil(n)
	return floor(n)


import math

def round_it(n):
	(dl, dr) = [len(d) for d in str(n).split('.')]
	if dl == dr:
		return round(n)
	elif dl > dr:
		return math.floor(n)
	else:
		return math.ceil(n)


import math

def round_it(n):
	(x, y) = str(n).split('.')
	x_string = len(str(x))
	y_string = len(str(y))
	if x_string < y_string:
		return math.ceil(n)
	if x_string > y_string:
		return math.floor(n)
	return round(n)


from math import ceil, floor

def round_it(n):
	(l, r) = map(len, str(n).split('.'))
	return ceil(n) if l < r else floor(n) if l > r else round(n)


from math import ceil, floor

def round_it(n):
	(x, y) = str(n).split('.')
	return ceil(n) if len(x) < len(y) else floor(n) if len(x) > len(y) else round(n)


def round_it(n):
	from math import floor, ceil
	f = [len(i) for i in str(n).split('.')]
	return round(n) if f[0] == f[1] else ceil(n) if f[0] < f[1] else floor(n)


import math

def round_it(n):
	print(n)
	test = str(n)
	counter = 0
	for val in test:
		if val == '.':
			break
		counter += 1
	if counter > (len(test) - 1) / 2:
		return math.floor(float(test))
	elif counter < (len(test) - 1) / 2:
		return math.ceil(float(test))
	else:
		return round(float(test))


from math import ceil, floor

def round_it(n):
	(a, b) = str(n).split('.')
	(l1, l2) = (len(a), len(b))
	if l1 < l2:
		return ceil(n)
	elif l1 > l2:
		return floor(n)
	return round(n)


def round_it(n):
	addition = 0
	temp = str(n).split('.')
	if len(temp) != 2:
		return n
	if len(temp[0]) < len(temp[1]):
		return int(temp[0]) + 1
	if len(temp[0]) > len(temp[1]):
		return int(temp[0])
	return round(n)


import math

def round_it(n):
	s = str(n)
	if not '.' in s:
		return 0
	vor = s.index('.')
	nach = len(s) - s.index('.') - 1
	if vor > nach:
		return math.floor(n)
	if vor < nach:
		return math.ceil(n)
	else:
		return round(n)


import math

def round_it(n):
	x = len(str(int(n)))
	y = len(str(n)) - x - 1
	return math.ceil(n) if x < y else math.floor(n) if x > y else round(n)


from math import floor, ceil

def round_it(n):
	string = str(n)
	point_ix = string.index('.')
	if len(string[:point_ix]) == len(string[point_ix + 1:]):
		return round(n)
	if len(string[:point_ix]) > len(string[point_ix + 1:]):
		return floor(n)
	return ceil(n)


from math import ceil, floor

def round_it(n):
	n = str(n)
	dot_index = n.find('.')
	before_dot = n[:dot_index]
	after_dot = n[dot_index + 1:]
	if len(before_dot) < len(after_dot):
		return ceil(float(n))
	elif len(before_dot) > len(after_dot):
		return floor(float(n))
	elif len(before_dot) == len(after_dot):
		return round(float(n))


def round_it(n):
	(l, r) = [len(str(i)) for i in str(n).split('.')]
	if l > r:
		return round(n - 0.5)
	if l < r:
		return round(n + 0.5)
	return round(n)


def round_it(n):
	(l, r) = str(n).split('.')
	pos = len(l) - len(r)
	return round(n) if pos == 0 else int(n) if pos > 0 else int(n + 1)


from math import ceil, floor

def round_it(n):
	s = str(n).split('.')
	n_pre = len(s[0])
	n_post = len(s[1])
	print(n_pre)
	print(n_post)
	if n_pre < n_post:
		return ceil(n)
	elif n_pre > n_post:
		return floor(n)
	else:
		return round(n)


import math

def round_it(n):
	(whole, fraction) = str(n).split('.')
	if len(whole) < len(fraction):
		final_n = math.ceil(n)
	elif len(whole) > len(fraction):
		final_n = math.floor(n)
	else:
		final_n = round(n)
	return final_n


import math

def round_it(n):
	a = str(n)
	b = a.find('.')
	if len(a) / 2 - 1 >= b:
		return math.ceil(n)
	elif len(a) / 2 <= b:
		return math.floor(n)
	else:
		return round(n)


from math import ceil, floor

def round_it(n):
	dot_index = str(n).find('.')
	len_int_part = dot_index
	len_dec_part = len(str(n)) - dot_index - 1
	if len_int_part < len_dec_part:
		return ceil(n)
	elif len_int_part > len_dec_part:
		return floor(n)
	else:
		return round(n)


from math import ceil, floor

def round_it(n):
	(ls, rs) = str(n).split('.')
	if len(ls) < len(rs):
		return ceil(n)
	if len(ls) > len(rs):
		return floor(n)
	return round(n)


def round_it(n):
	a = str(n).split('.')
	b = [int(x) for x in a]
	if b[0] > b[1]:
		return round(n - 0.5)
	else:
		return round(n + 0.5)


from math import ceil, floor

def round_it(n):
	str_n = str(n)
	x = str_n.split('.')[0]
	y = str_n.split('.')[1]
	if len(x) < len(y):
		return ceil(n)
	if len(x) > len(y):
		return floor(n)
	return round(n)


def round_it(n):
	import math
	point = str(n).index('.')
	mayor = str(n)[0:point]
	menor = str(n)[point + 1:]
	if len(mayor) > len(menor):
		return math.floor(n)
	elif len(mayor) < len(menor):
		return math.ceil(n)
	elif len(mayor) == len(menor):
		return round(n)


import math

def round_it(n):
	number_as_string = str(n)
	size_of_number = len(number_as_string) - 1
	index_of_decimal = number_as_string.index('.')
	if size_of_number / 2 == index_of_decimal:
		return round(n)
	elif size_of_number / 2 > index_of_decimal:
		return math.ceil(n)
	else:
		return math.floor(n)


import math

def round_it(n):
	nn = str(n)
	(lhs, rhs) = nn.split('.')
	if len(lhs) > len(rhs):
		return math.floor(n)
	elif len(lhs) < len(rhs):
		return math.ceil(n)
	else:
		return round(n)