Solved

The Equiv of VB6's Format in C#

Posted on 2004-08-10
4
1,590 Views
Last Modified: 2008-03-17
Hello

I am recieveing a foramt string from a database descibing it's current format in a C# class.

#,##0.00;(#,##0.00)

which descibes how to format a number (comma's for thousands and brackets for negative numbers)

In my old VB6 days I used to use the Format function
sVal="100000"
sVal2="-100000"
sFormat="#,##0.00;(#,##0.00)"
sMyStr=Format(sFormat,sVal)
' would return 1,000,000
sMyStr=Format(sFormat,sVal2)
' would return (1,000,000)

I've looked around and the closest I can find is String.format but it doesn't accept my format as a valid format. They do have the equivilant of what I want but then I would have to evaluate every possible format and find the equivilant.

Is there something obvious (which I suspect) I am missing ???

tia
0
Comment
Question by:GillyTheTaffy
4 Comments
 
LVL 20

Expert Comment

by:TheAvenger
ID: 11770088
I haven't met a function that can do directly what you want. I suppose you have to write it yourself :-((
0
 
LVL 1

Accepted Solution

by:
GillyTheTaffy earned 0 total points
ID: 11770213
not so !!

just working through the issue now

String.format is the way to go but I needed to add a few chars to the format string - see below

//original foramt string (or close ennough - they were a few extra bits
// the the DB returned that I trimmed)
sFormat="#,##0.00;(#,##0.00)";

// string that I needed
string sFullFormat="{0:#,##0.00;(#,##0.00)}";

// value I want to format (note int not string)
int iVal=1000000;

// This now works
String sFormatedVal=String.format(sFullFormat,iVal);

wahhoooo

thanks for responding anyway

Graham
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 11783498
Can you close this question?  Help topic is here for hints on how to close:

Closing Questions
http://www.experts-exchange.com/help.jsp#hi5

Bob "Cleanup Volunteer"
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

744 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now