Solved

number format in asp.net

Posted on 2006-11-07
13
269 Views
Last Modified: 2013-11-25
i have data showen in a coulmn in table which contains this value in this format
1500
11560
115601
1212342
11342342
445654355
4456543550
4456543550.12
99300888222
99300888222.001
how can i show this value in this format
1,500.000
11,560.000
115,601.000
1,212,342.000
11,342,342.000
445,654,355.000
4,456,543,550.000
4,456,543,550.012
99,300,888,222.000
99,300,888,222.001

i need this format by asp.net ,can any one help me please ??
best regards
0
Comment
Question by:thaerali
  • 4
  • 4
  • 2
  • +1
13 Comments
 
LVL 10

Expert Comment

by:orbulat
ID: 17887626
0
 
LVL 11

Expert Comment

by:ethoths
ID: 17887954
If the number is in intMyNumber then

intMyNumber.ToString("#,###.##")

will do it
0
 
LVL 11

Expert Comment

by:ethoths
ID: 17888034
Sorry, that should have been

intMyNumber.ToString("#,###.000")
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
LVL 20

Expert Comment

by:REA_ANDREW
ID: 17888121
My version would be

Response.Write(String.Format("{0:#,##0.000;(#,##0.000);Nothing}", 12345670.55));
0
 
LVL 20

Expert Comment

by:REA_ANDREW
ID: 17888128
I got this expression from orbulat's  post.  Just trying to give you a version without the £ character

Andrew
0
 
LVL 11

Accepted Solution

by:
ethoths earned 63 total points
ID: 17888159
If you want an object oriented solution to use in asp.net then my solution is the best. The primary purpose of string.format is to do place holder replacements to string to make concatenation easier...

String.Format("This is a {0} I {1} earlier", "string", "made")

Produces: This is a string I made earlier.

Although it can be used to do the formatting you require, under .Net there is a better way. Surely

intMyNumber.ToString("#,###.##")

is easier to read (and debug) than

String.Format("{0:#,##0.000;(#,##0.000);Nothing}", 12345670.55)

0
 
LVL 20

Assisted Solution

by:REA_ANDREW
REA_ANDREW earned 62 total points
ID: 17888186
not really I would find both easy to read and debug. Depends on your level on understanding I would imagine.

For example, Regular Expressions to somebody new are not easy to read. But like anything, when you learn something it becomes clear.

both achieve the desired result and also we have given the Person asking the question various options, which in turn can lead to further paths of learning and research.

This is why Experts Exchange is so good, you do not expect one answer, but several, and hopefully, all are correct...

Andrew

:)
0
 
LVL 11

Expert Comment

by:ethoths
ID: 17888202
I understand what you  are saying REA_ANDREW but ultimately our code will be maintained by others. Sometimes those 'others' will not be a skilled as us and as used to reading regular expressions as us. It is our job to do things in as clear and as simple way as possible for this reason. One should only ramp up the complexity if it is absolutley warrented by the problem being addressed.
0
 
LVL 20

Expert Comment

by:REA_ANDREW
ID: 17888206
Point taken, Good comment and I totally agree!

:-)

Andrew
0
 
LVL 11

Expert Comment

by:Vivek Thangaswamy
ID: 17888610
0
 
LVL 11

Expert Comment

by:Vivek Thangaswamy
ID: 18131328
Hi thaerali

Is my suggestion helped you?
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Run time Error 4 47
Message not shown 5 49
Is there any online third party tool For Conducting Online Exams like Freelancer site ? 7 37
When should I use a controller? 3 34
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question