0
could, help me with the following situation:
I have a Numeric field (21,2) and need to format it for a specific layout, as below.
Example of Input’s:
VALOR1: 3500.31 -> After Formatting: +0000000003500.31
VALOR2: -3000 -> After Formatting: -0000000003000.00
VALOR3: 2000.00 -> After Formatting: +0000000002000.00
I’m using the function below to fill the 0 to the left and validate the signal, but I have a problem, for cases where the input is an integer, so the field in is in the format #.00 :
Output: +0000000000003000
Function:
function leadingZero(value, totalWidth, paddingChar) {
var length = totalWidth - value.toString().length + 1;
return Array(length).join(paddingChar || '0') + value;
};
if (total_amount >=0){
var total_amount = '+' + leadingZero(total_amount,20);
} else {
var total_amount = '-' + leadingZero(replace(total_amount,'-',''),20);
}
Thank you!
Again? What’s the difference to your other question? https://answall.com/q/257573/5878
– Woss
Possible duplicate of Javascript function for field formatting
– Oralista de Sistemas
Although you already have an answer, your question is a bit confused: where does the parameter come from
paddingChar
? Are you trying to insert new value into the field? This is PHP?– Sam
@The paddingChar is by default 0, however it is the value to which I will add the string.
– John Dude
Sergio’s answer didn’t solve the problem?
– Sam
@In the end, yes..
– John Dude