473,387 Members | 1,455 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

String formating issue with doubles

Private mFormat As String = "##.##"

Return DirectCast(value, Double).ToString(mFormat) returns "" when
value is 0.0

I would prefer that it return "0". Does anyone have some advice?

Thanks for any help

Jeremy Kitchen

Mar 12 '07 #1
5 947
Try this fromat string to see if it gives you what you want (I think
it should always show a leading zero before the decimal point).

"#0.##"

================
Clay Burch
Syncfusion, Inc.

Mar 12 '07 #2
Jeremy Kitchen wrote:
Private mFormat As String = "##.##"

Return DirectCast(value, Double).ToString(mFormat) returns "" when
value is 0.0

I would prefer that it return "0". Does anyone have some advice?
The # indicates an optional number, but you can use 0 for "always a number,
and 0 if there's nothing in there".

Private mFormat As String = "#0.##"

Andrew
Mar 12 '07 #3
Hello, Jeremy,

You could try:

Private mFormat As String = "#0.##"

Cheers,
Randy

Jeremy Kitchen wrote:
Private mFormat As String = "##.##"

Return DirectCast(value, Double).ToString(mFormat) returns "" when
value is 0.0

I would prefer that it return "0". Does anyone have some advice?

Thanks for any help

Jeremy Kitchen
Mar 15 '07 #4
Hello R. MacDonald,

Hmm... You could enclose the statement in Val

Val(DirectCast(value, Double).ToString(mFormat) )
-- You can do anything with a little bit of 'magination.

-- I've been programming so long, my brain is now software.
Hello, Jeremy,

You could try:

Private mFormat As String = "#0.##"

Cheers,
Randy
Jeremy Kitchen wrote:
>Private mFormat As String = "##.##"

Return DirectCast(value, Double).ToString(mFormat) returns "" when
value is 0.0

I would prefer that it return "0". Does anyone have some advice?

Thanks for any help

Jeremy Kitchen

Mar 15 '07 #5
That doesn't produce a formatted string.

Cyril Gupta <cyrilgupta wrote:
Hello R. MacDonald,

Hmm... You could enclose the statement in Val

Val(DirectCast(value, Double).ToString(mFormat) )
-- You can do anything with a little bit of 'magination.

-- I've been programming so long, my brain is now software.
>Hello, Jeremy,

You could try:

Private mFormat As String = "#0.##"

Cheers,
Randy
Jeremy Kitchen wrote:
>>Private mFormat As String = "##.##"

Return DirectCast(value, Double).ToString(mFormat) returns "" when
value is 0.0

I would prefer that it return "0". Does anyone have some advice?

Thanks for any help

Jeremy Kitchen

--
Göran Andersson
_____
http://www.guffa.com
Mar 15 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Jessica | last post by:
Hi, I have a question regarding the object-oriented issue. I understand that a class is a type. I have an array class. Now say that I want to implement an algorithm A that uses the array class....
7
by: Daniel Lidström | last post by:
Hi, I'm currently using this method to extract doubles from a string: System::String* sp = S" "; System::String* tokens = s->Trim()->Split(sp->ToCharArray()); m_Northing =...
1
by: Matt Garman | last post by:
I've got some code that generates a report for the user. The report is shown with explanatory verbage. The text is relatively long, and also has some simple formatting (paragraphs, bulleted...
5
by: JustSomeGuy | last post by:
I have a string that looks like: "123.45:123.45" I am using sscanf "%f%*c%f" to extract the two floats and ignore the colon. However there may be more than two floats.... Is there perhaps a...
2
by: Bob | last post by:
I'm having trouble the string.Format() throwing exceptions and I can't figure out what I am doing wrong. Given the following setup code: string str = { "one", "two", "three", "four" }; double...
18
by: Joah Senegal | last post by:
Hello all, I'm trying to print a string on my screen... But the string comes from a variable string... This is the code #include <cstdlib> #include <iostream> #include <string> using...
4
by: Ciaran | last post by:
Hi can someone give me hand with this please? What's the best way to extract the extension from the url? example: $string="http://www.domain.co.uk/anypage.html" In this example, I'd be...
1
by: nico | last post by:
Hi, I need to do a lot of string formating, and I have strings and/or unicode strings and when I do the following: "%s %s" % (u'Salut', 'H\xe4llo'), I get an exception : UnicodeDecodeError:...
9
nine72
by: nine72 | last post by:
Ok, so I have figured out how to parse an custom returned XML doc (actually a string that I made into a doc for testing). At this point I am attempting to integrate my parse routine into my main...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.