Solved

The Equiv of VB6's Format in C#

Posted on 2004-08-10
4
1,602 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: 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!

Question has a verified solution.

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

Suggested Solutions

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

752 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