Skip to main content
Inspiring
November 18, 2016
Question

$50.00 + $50.00 concatenated as $5050.00.

  • November 18, 2016
  • 1 reply
  • 440 views

I have several numeric formatted fields scripted to be added, with a sum displayed in a "total" field. Sometimes the total is correct, so that for instance $50.00 + $50.00  totals as $100.00, but at other times $50.00 + $50.00 appears concatenated, as $5050.00. I cannot find what may be causing this and would appreciate help correcting this.

This topic has been closed for replies.

1 reply

Inspiring
November 18, 2016

Something is causing one of the values to appear to be a string.

What is the format of the fields?

Are there any null or empty fields being used in the calculation?

One can use the Number constrictor to force values to numerics.

If you include the $ symbol you are creating a string not a number.

JR Boulay
Community Expert
Community Expert
November 20, 2016

Hi.

To force values to numerics you can multiply by 1:

var nTotal = (50.00 * 1) + (50.00 * 1);

var sTotal = "$" + nTotal;

Acrobate du PDF, InDesigner et Photoshopographe