consultancy chorley ASP.NET Server Side Scripting Wigan
Website Development Radcliffe

A Coder's Notes

Email :
bespoke invoice systems Standish Information Technology Advice Worsley
    development systems Ramsbottom
data manipulation Farnworth access databases Whitefield SQL connections Atherton
online accessible software Leyland software compatible Coppull

Get connected and Online Tottington
remote management Makerfield code and design Aspull

ASP.NET String Format Currency With and WITHOUT Decimal places - pence - 21/12/2010

ASP.NET has a very simple method of formating a string into currency

String.Format ("{0:c}", mynumber)

so if mynumber = "123.00" then well get

But if we DO NOT want the decimal places, the pence, the cents or whatnot then

String.Format ("{0:c0}", mynumber)

NOTE the extra "0" ofer the "c". This will now give £123


Even better for longer numbers

String.Format ("{0:c0}", "123456.00")

wil give £123,456

A nice tidy comma to help distinguish the numbers.

Post A Comment

Name Comment
Steve G Sorted, so simples that
masoud Thanks a lot it was grate it helped me
programming services specialist
Valid XHTML 1.0 Transitional