Created
January 22, 2019 00:20
-
-
Save th3d0g/6fcbb04af035f021617d2de2a184e4ed to your computer and use it in GitHub Desktop.
Created with Copy to Gist
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
| function roundToHalf(value) { | |
| var converted = parseFloat(value); // Make sure we have a number | |
| var decimal = (converted - parseInt(converted, 10)); | |
| decimal = Math.round(decimal * 10); | |
| if (decimal == 5) { return (parseInt(converted, 10)+0.5); } | |
| if ( (decimal < 3) || (decimal > 7) ) { | |
| return Math.round(converted); | |
| } else { | |
| return (parseInt(converted, 10)+0.5); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment