Page 1 of 1

Number formatting help

Posted: Thu Apr 01, 2021 7:50 pm
by orangezero
I have a slightly unique situation I'm trying to figure out. I need people to input numbers quickly, but still save in the correct format. Let me give a few examples to illustrate:

user types "2" and then it auto formats to "+2.00"
user types "-2" and then it auto formats to "-2.00"
user types "1.5" and it auto formats to "+1.50"

I see where to specify decimal point and # of zeros in nubuilder, but I'm not sure about adding the + or - automatically in a format the software understands. I can get it to add +/- easily enough in front of a number... just not be selective depending on what is typed in.

One option I thought to save time was to separate the + and - into a new area that users would select before each number, but I hope there is a simpler way.

An alternative would be to have a drop down of available numbers to pick from and just have -2.00 and +2.00 in that list also, but I haven't figured out if typing or selecting from a list is going to be easier for users. I'm open to advice on this. I just have my past experience as a user thinking the option I'm not using must be faster, ha.

Thank you for even reading all this...

Re: Number formatting help

Posted: Thu Apr 01, 2021 8:11 pm
by kev1n
You'd have to use a Text format for "Input Type (and class)" and in the database a varchar column type in order to have a "+" sign stored in the database.

Adding an onblur JavaScript event to the object's Custom Code will format the number accordingly when the field loses focus.

Code: Select all

let v = $(this).val();
let num = parseFloat($(this).val());
let fixed = num.toFixed(2);
fixed = fixed > 0 ? '+' + fixed : fixed;
$(this).val(fixed).change();

Re: Number formatting help

Posted: Thu Apr 01, 2021 8:42 pm
by orangezero
Your speed is most impressive! Many thanks to you and the others who have took up the nuBuilder mantle.

Re: Number formatting help

Posted: Thu Apr 01, 2021 8:53 pm
by kev1n
Thanks orangezero , you are the most welcome!