PrintNW

February 15th, 2013, 08:28 AM

I have a calculation script that is meant to subtract one dollar amount from another and then format the result into either ##¢ (for cents results) and $##.## (for dollar results).

I've worked out the subtraction, but the formatting is getting thrown off because the the result of the subtraction id not correct. For example, when I subtract 6.49-5.89 the result is 0.6000000000000005 and when I subtract 7.00-5.89 the result is 1.1100000000000003. This all occurs even before my currency formatting script begins.

Can someone please look at the code below and help me determine how to correct it? Or, if possible, provide me with an alternative script to accomplish what I want?

Thanks in advance.

Lee Francis,

Print NW

var prc1 = Field("LRG Cheese Pizza Only Price");

var prc2 = Field("Base Price - Pepperoni");

var totalAmount = StringToNumber(prc1 - prc2);

// Used only to see how FPD was calculating

// return totalAmount

if (totalAmount.length < 3)

return FormatNumber("##", totalAmount)+'¢';

else

return '$'+ FormatNumber("#,###.##", totalAmount);

I've worked out the subtraction, but the formatting is getting thrown off because the the result of the subtraction id not correct. For example, when I subtract 6.49-5.89 the result is 0.6000000000000005 and when I subtract 7.00-5.89 the result is 1.1100000000000003. This all occurs even before my currency formatting script begins.

Can someone please look at the code below and help me determine how to correct it? Or, if possible, provide me with an alternative script to accomplish what I want?

Thanks in advance.

Lee Francis,

Print NW

var prc1 = Field("LRG Cheese Pizza Only Price");

var prc2 = Field("Base Price - Pepperoni");

var totalAmount = StringToNumber(prc1 - prc2);

// Used only to see how FPD was calculating

// return totalAmount

if (totalAmount.length < 3)

return FormatNumber("##", totalAmount)+'¢';

else

return '$'+ FormatNumber("#,###.##", totalAmount);