Solved

The Equiv of VB6's Format in C#

Posted on 2004-08-10
4
1,593 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

914 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

17 Experts available now in Live!

Get 1:1 Help Now