Last active
March 13, 2020 05:02
-
-
Save Pie001/f528f3feeb12ff462b2ca1e727514567 to your computer and use it in GitHub Desktop.
clear_decimal_point.js
This file contains 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
function clear_decimal_point(value) { | |
// 3.20 -> 3.2, 3.00 -> 3 | |
var s = value.split("."); | |
if (s.length == 1) { | |
return value; | |
} | |
var zeroCount = 0; | |
for (i = 0; i < s[1].length; i++) { | |
if (s[1].substring(s[1].length - (i + 1), s[1].length - i) == "0") { | |
zeroCount += 1; | |
} | |
} | |
if (zeroCount == s[1].length) { | |
zeroCount += 1; | |
} | |
return value.substring(0, value.length - zeroCount); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment