Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Forcing decimal places 1

Status
Not open for further replies.

Sensibilium

Programmer
Apr 6, 2000
310
GB
I've looked through my ASP book for a way to force a certain number of decimal places to be displayed.

IE:
£2.00 using 'Round' function outputs "£2"
£3.50 becomes £3.5

I'm sure there is an easy answer to this but I can't find it anywhere!

ahdkaw
ahdkaw@ots.zzn.com
'If anythign can go wrong, it will'
 
Lets see your code.... ;-)

DougP, MCP
dposton@universal1.com

Ask me how Bar-codes can help you be more productive.
 
Okay DouggyBoy, here you go:

[tt]Response.Write &quot;<td align=right><p class=list>£&quot; & Round(orsProducts(&quot;RRP&quot;),2) & &quot;</p></td>&quot;[/tt]

The RRP field in the Products Table is setup as Currency.

It's that small!

ahdkaw
ahdkaw@ots.zzn.com
'If anythign can go wrong, it will'
 
Well then, thanks to I got my answer to this (it's so bloody simple, I'm surprised no-one here knows it).

To format a number with a specific number of decimal places (in this case, 2) then this is the function to use:

[tt]FormatNumber(orsSomeRecordset(&quot;MyNumber&quot;), 2) [/tt]

If your number is Currency, then try:

[tt]FormatCurrency(orsSomeRecordset(&quot;MyCurrency&quot;),2)[/tt]

Of course, if your server is not in your country then it will append whatever the server has setup for their Currency type.

The safest way to deal with formatting a currency field is as follows:

[tt]Response.Write &quot;£&quot; & FormatNumber(orsSomeRecordset(&quot;MyCurrency&quot;), 2)[/tt]

Easy, huh?

ahdkaw
ahdkaw@ots.zzn.com
'If anythign can go wrong, it will'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top