Created
August 14, 2012 06:55
-
-
Save island205/3347070 to your computer and use it in GitHub Desktop.
数据处理
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| isInteger=(n)-> | |
| n%1 == 0 | |
| foo=(num)-> | |
| num=parseInt num, 10 | |
| re=[] | |
| if num == 0 | |
| return num | |
| while num > 0 | |
| remainder = num%1000 | |
| num=parseInt(num/1000,10) | |
| re.unshift remainder | |
| return re.join "," | |
| bar=(num)-> | |
| if isInteger num | |
| foo num | |
| else | |
| nums=(num+"").split "." | |
| foo(nums[0]) + "." + foo(nums[1].split("").reverse().join("")).split("").reverse().join("") | |
| console.log bar 0 | |
| console.log bar 1 | |
| console.log bar 23 | |
| console.log bar 234 | |
| console.log bar 2345 | |
| console.log bar 23456 | |
| console.log bar 234567 | |
| console.log bar 2345678 | |
| console.log bar 0.0 | |
| console.log bar 1.1 | |
| console.log bar 23.23 | |
| console.log bar 234.234 | |
| console.log bar 2345.2345 | |
| console.log bar 23456.23456 | |
| console.log bar 234567.234567 | |
| console.log bar 2345678.2345678 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment