Skip to content

Instantly share code, notes, and snippets.

@Pie001
Last active March 13, 2020 05:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Pie001/f528f3feeb12ff462b2ca1e727514567 to your computer and use it in GitHub Desktop.
Save Pie001/f528f3feeb12ff462b2ca1e727514567 to your computer and use it in GitHub Desktop.
clear_decimal_point.js
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