Entries for month: October 2009

Todays' Ad

cfmap tag for Google Map

ColdFusion , ColdFusion 9 1 Comment »

I really impressed with CFMAP tag in ColdFusion 9. It eliminates javascript code for google map api. Now google map integration is so easy that will finish in just two steps 1. Get google map API key for your domain. 2. Use CFMAP tag and render map in HTML page.

After getting API key we need to tell coldfusion about our MAP API key either by giving in cfajaximport tag or application.cfc file. You can specify api key in cfajaximport tag if you are want to use this in single page only but if planning to use google map in site wide then better idea to specify in Application.cfc. Below are both way to specify key.

<cfajaximport params="#{googlemapkey='ABQIAAAABvdd0PabCkL4zGc4TF1t6hT2yXp_ZAY8_uf....'}#" />
OR
<cfset this.googlemapkey="ABQIAAAABvdd0PabCkL4zGc4TF1t6hT2yXp_ZAY8_uf.....">

Read more...

Problem with Real Number operation and dollarFormat function

2 Comments »

Today I come across really strange problem. I am just trying to execute following code.

<cfset invoiceAmount=75.00>
<cfset paidAmount=73.12>
<cfset discount=1.88>
<cfset dueBalance = invoiceAmount - paidAmount - discount>
<cfoutput>Balance Due: #dollarFormat(dueBalance)#</cfoutput>

What should be result? Ofcourse Balance Due: $0.00 (what a stupid question?). Even I have thought same but result is really surprising and its Negative Zero
Output:
Balance Due: ($0.00)

This is because of rounding problem of mathematical operation on Real number. Subtract operation on above numbers (invoiceAmount - paidAmount - discount) produce -4.4408920985E-015 as result which is almost zero (but not zero). Now I was applying dollarFormat function which display number to upto two decimal point (not rounding to two decimal point) so result is -0.00 and will display as ($0.00).

Best solution I found is to apply Round function on number prior to apply dollarFormat function. I have just tried below one and it work for me.

<cfset invoiceAmount=75.00>
<cfset paidAmount=73.12>
<cfset discount=1.88>
<cfset dueBalance = invoiceAmount - paidAmount - discount>
<cfoutput>
    Balance Due: #dollarFormat(Round(dueBalance*1000)/1000)#
</cfoutput>

Round(dueBalance*1000)/1000.00 is work fine for me to display what exactly I want (instead of NEGATIVE ZERO). My intension was excluding numbers on 3rd or greater position after decimal point as it was creating problem for me.

Powered by Mango Blog. Design and Icons by N.Design Studio | Menu Apycom
RSS Feeds