Skip to main content
Participant
January 6, 2007
Answered

Problems adding and subtracting - End up w/ Exponential value

  • January 6, 2007
  • 1 reply
  • 311 views
I have a problem with a script i'm writing... Basically when I subtract one vale from another and the product should be zero, i end up with a exponential value insted. What is really strange, most of the time it does come out with a correct balance of zero?
Here is the script... the values are stores as nvarchar on the SQL server.
ANY HELP WOULD BE GREATLY APPRECIATED!!! I Have been trying to figure this out for a couple of weeks now.

<cfset DebitTotal = 0>
<cfset CreditTotal = 0>
<cfset CreditAdjust = 0>
<cfset DebitAdjust = 0>
<cfoutput query="GetEntries">
<tr>
<td>#EntryDate#</td>
<td>#EntryDescription#</td>
<td>#EntryType#</td>
<td><cfif #Debit# EQ 0>
 
<cfelseif EntryType EQ 'RMA'>
(#Debit#)
<cfset DebitAdjust = #DebitAdjust# + #Debit#>
<cfelse>
#Debit#
<cfset DebitTotal = #Debit# + #DebitTotal#>
</cfif></td>
<td><cfif #Credit# EQ 0>
 
<cfelseif EntryType EQ 'CAA'>
(#Credit#)
<cfset CreditAdjust = #CreditAdjust# + #Credit#>
<cfelse>
#Credit#
<cfset CreditTotal = #CreditTotal# + #Credit#>
</cfif>
</td>
</tr>
</cfoutput>
<cfset CreditTotalAdjusted = #CreditTotal# - #CreditAdjust#>
<cfset DebitTotalAdjuested = #DebitTotal# - #DebitAdjust#>
<cfset Balance = #DebitTotalAdjuested# - #CreditTotalAdjusted#>
    This topic has been closed for replies.
    Correct answer JZubrzycki
    OK, I got it fixed (I think). Being that I am just adding and subtracting currency already rounded to two decimal places. I used DecimalFormat() before I try to subtract my like values and it looks like it is holding and returning what I need.

    I ended up getting this solution from the following thread.
    http://www.adobe.com/cfusion/webforums/forum/messageview.cfm?forumid=1&catid=3&threadid=1228485&highlight_key=y&keyword1=subtract

    1 reply

    JZubrzyckiAuthorCorrect answer
    Participant
    January 6, 2007
    OK, I got it fixed (I think). Being that I am just adding and subtracting currency already rounded to two decimal places. I used DecimalFormat() before I try to subtract my like values and it looks like it is holding and returning what I need.

    I ended up getting this solution from the following thread.
    http://www.adobe.com/cfusion/webforums/forum/messageview.cfm?forumid=1&catid=3&threadid=1228485&highlight_key=y&keyword1=subtract