Created
May 17, 2020 03:48
-
-
Save cpaul007/c964f55c38188bdd9c2be4ecf073deb4 to your computer and use it in GitHub Desktop.
Numver Fortmat in JavaScript
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
jQuery(document).ready(function($){ | |
//* #ff_10_value_1,#ff_10_value_2 are input field ID. | |
$('#ff_10_value_1,#ff_10_value_2').on('keyup blur', function(){ | |
var value = $('#ff_10_sum_ff').val(); | |
//* #ff_10_sum_ff is the calcualtion field ID where value is showing | |
$('#ff_10_sum_ff').val( numberFormat(value, 2, '.', ',') ); | |
}); | |
}); | |
function numberFormat (number, decimal_pos, decimal_sep, thousand_sep) { | |
var ts = ( thousand_sep == null ? ',' : thousand_sep ) | |
, ds = ( decimal_sep == null ? '.' : decimal_sep ) | |
, dp = ( decimal_pos == null ? 2 : decimal_pos ) | |
, n = Math.floor(Math.abs(number)).toString() | |
, i = n.length % 3 | |
, f = ((number < 0) ? '-' : '') + n.substr(0, i) | |
; | |
for(;i<n.length;i+=3) { | |
if(i!=0) f+=ts; | |
f+=n.substr(i,3); | |
} | |
if(dp > 0) | |
f += ds + parseFloat(number).toFixed(dp).split('.')[1] | |
return f; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Keep in mind that comma will not work in Fluent Form numeric field. Because validation script is blocking it.