Forum Moderators: open

Message Too Old, No Replies

Currency data formatting with ASP/vb

need to display amounts correctly

         

hairsuper

9:26 am on Sep 4, 2005 (gmt 0)

10+ Year Member



i need to format currency values correctly i.e. 3.90, currently this sort of number gets rounded so it looks like 3.9

how do i fix it to 3.90, and put a £ in front of it so its displayed £3.90, concatenating it to the front is no good as i need negative amounts to be shown as -£3.90 not £-3.90

Thank you

aspdaddy

9:37 am on Sep 4, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can do it using the abs() and FormatNumber() functions in vbScript.


function myFormat ( intAmount )
dim sTemp
sTemp=formatNumber(intAmount,2)
if intAmount < 0 then
sTemp ="-£" & formatNumber(abs(intAmount),2)
else
sTemp ="£" & formatNumber(intAmount,2)
end if
myFormat =sTemp
end function

msgBox myFormat (-10.1)
msgbox myFormat (-10)
msgbox myFormat (1)
msgbox myFormat (25.2)

hairsuper

12:02 pm on Sep 4, 2005 (gmt 0)

10+ Year Member



thank you that works fine, but is there a way to do it without a function? i had a vb manual which im sure you could format currency datatypes with mask characters like £###.## that sort of thing, is it possible to do that or have i dreamed it?

aspdaddy

4:40 pm on Sep 4, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Theres a format currency function but I havent had cause to use it.

emsaw

4:18 am on Sep 6, 2005 (gmt 0)

10+ Year Member



hairsuper,

Try this:


FormatCurrency("3.90", 2, 0,0,0)

that's:
NumberToFormat, NumberOfDecimalPlaces, IncludeLeadingZero, NegativeNumberParens, UseGroupSeparator

HTH,

mark