Has anyone used autonumeric.js

Has anyone used autonumeric.js
0

#1

I am trying to implement some commas and decimals using autonumeric.js. I have hit a bump or two. When i type text in my first input, i get a comma, and a decimal (yay), but when my calculation happens and auto populates the fourth input, i only get a comma, no decimal. Code is below

<form id="form1">
  <h3>Lifetime Value Calculator</h3>
   <input value="" type="text" class='num1 demo'/> 
   <input value="" type="text" class='num2'/>
   <input value="" type="text" class='num3'/>          
   <input value="" type="text" class='num4'/>
 </form>

This is my calculation which adds the fields together:

 $(".num1, .num2, .num3").change(function() {
   $(".num4").prop("readonly", true).val($(".num1").val() * $(".num2").val() * $(".num3").val());
    });

And here is what I have so far using autoNumeric.js. Again, the math works fine, but the comma and decimal only works for .num1 but not for .num4. For that one, i only get a comma

$('.num1, .num4').each(function() {
   var autoNumericInstance = new AutoNumeric($(this)[0], AutoNumeric.getPredefinedOptions().numericPos.dotDecimalCharCommaSeparator);
  });

Any help would be GREATLY appreciated


autoNumeric.js ..... anyone, PLEASE help!
#2

I posted last week but no luck, so i am giving this another shot. I am trying (and failing) to implement autoNumeric.js into this.

I have a form that does simple math, and i am trying to add commas and decimals for numbers…so 3000 is 3,000 and and a dollar field would be 50.00, or 5,000.00

I have tried and failed, maybe i am not reading the docs properly but cant seem to wrap my head around this. For the example below, the first and last fields would be dollar values. Please assist.


#4

Hi,
I have not used autoNumeric.js. And I am a little confused about the form is actually supposed to work.

I do see that you have a $0.00 on each line. This is a good start…

I would think that you could check the character length before the decimal. If there is no comma, and if the length is more than 4, then insert a comma before the final 3 characters that are in front of the decimal.


#5

thanks for the response. I was able to figure this out after a lot of documentation reading. Much appreciated


#6

I’m glad you got it working. Can you please check this question as resolved.

And, for future coders with similar questions, can you please share your solution?
Thank you.