Skip to main content
Participating Frequently
November 27, 2006
Question

Commercial (Mercantile) Rounding?

  • November 27, 2006
  • 2 replies
  • 2353 views
Greetings,

in order to calculate something i need to multiply some values on CF5.0

a = 1690,00 which is a price
b = 0.0025 which is a insurance rate
x = the result from a * b

1690,00 * 0,0025 = 4,225 or <cfset x = a * b>

All fine so far... but the result returned is alway 4,22, I need that result to be commercial rounded up to 4,23. Seems to be simple though, but i havent found any solution to specify what type of rounding i prefer...

Any help would be much appreciated...
    This topic has been closed for replies.

    2 replies

    Inspiring
    November 27, 2006
    Try numberformat().
    Inspiring
    November 27, 2006
    How are you getting 4.22?
    wulfkauAuthor
    Participating Frequently
    November 27, 2006
    <cfset a = "1690.00">
    <cfset b = "0.0025">

    <cfset x = a * b>

    <cfoutput>x</cfoutput> ==> 4.225

    So, what to do next? I need this as a number with two decimals. So i used LSNumberFormat. X then displays as 4,22 and not as 4,23 as i want him to do...

    <cfoutput>#LSCurrencyFormat(x, "none")#</cfoutput> ==> 4,22
    <cfoutput>#DecimalFormat(x)#</cfoutput> ==> 4.22

    Yeah, i know... i can do something dirty like checking the decimals manually and to increase them or something like that, but isnt there any better way? Or is there a fault in my thoughts? Have i overlooked something? :-)
    November 27, 2006
    You must specify the correct mask with LSNumberFormat:

    <cfset SetLocale ("German (Standard)")>
    <cfoutput>#LSNumberFormat (x, "0.99")#</cfoutput> ==> 4,23<br>