Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1625
  • Last Modified:

The Equiv of VB6's Format in C#

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
GillyTheTaffy
Asked:
GillyTheTaffy
1 Solution
 
TheAvengerCommented:
I haven't met a function that can do directly what you want. I suppose you have to write it yourself :-((
0
 
GillyTheTaffyAuthor Commented:
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
 
Bob LearnedCommented:
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now