?
Solved

The Equiv of VB6's Format in C#

Posted on 2004-08-10
4
Medium Priority
?
1,621 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

719 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