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

IT Services And Support

Email : ren@techsolus.co.uk
Mobile Phone : 0788 68 41 411
Answerphone : 01204 469683
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
£123.00

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

Brilliant!

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 asp.net specialist
Valid XHTML 1.0 Transitional
Admin
GD