Click here to Skip to main content
15,921,530 members
Home / Discussions / C#
   

C#

 
AnswerRe: Convert String to decimal Pin
Judah Gabriel Himango22-Feb-06 4:10
sponsorJudah Gabriel Himango22-Feb-06 4:10 
GeneralRe: Convert String to decimal Pin
cppdotnet22-Feb-06 4:16
cppdotnet22-Feb-06 4:16 
GeneralRe: Convert String to decimal Pin
Judah Gabriel Himango22-Feb-06 4:29
sponsorJudah Gabriel Himango22-Feb-06 4:29 
GeneralRe: Convert String to decimal Pin
Dan Neely22-Feb-06 4:37
Dan Neely22-Feb-06 4:37 
GeneralRe: Convert String to decimal Pin
Judah Gabriel Himango22-Feb-06 4:44
sponsorJudah Gabriel Himango22-Feb-06 4:44 
GeneralRe: Convert String to decimal Pin
cppdotnet22-Feb-06 5:02
cppdotnet22-Feb-06 5:02 
GeneralRe: Convert String to decimal Pin
Dan Neely22-Feb-06 6:15
Dan Neely22-Feb-06 6:15 
GeneralRe: Convert String to decimal Pin
Qhalis22-Feb-06 4:59
Qhalis22-Feb-06 4:59 
The problem is that there is no single format that will achieve your goal


Say you have 88.0 and 88888.888

Console.WriteLine("{0Blush | :O ##}", num)

will give you

88.0
88888.888

the problem is that if you have another number of finer precision, say 99.1234, it will be rounded to 99.124.

If you use the general format g

Console.WriteLine("{0:g}", num)

then you will get

88
88888.888
99.1234


If you have a hard need to display 88 as 88.0 then you will probably need to use two format strings


Dim nums() As Double = {88, 88888.888}
Dim numFmt As String

For Each num As Double In nums

Dim tmpNum As Double = System.Math.Abs(num)
If (System.Math.Floor(tmpNum) = tmpNum) Then
numFmt = "#.0"
Else
numFmt = "g"
End If

Dim exprFmt As String = "{0:" & numFmt & "}"

Console.WriteLine(exprFmt)
Console.WriteLine(String.Format(exprFmt, num))

Next

End Sub


NOTE: When testing this, it works well for Doubles but not singles. Don't know why

hth,
Alan.




if (





QuestionHaving Scrollbars to MDI form? Pin
majidbhutta22-Feb-06 3:50
majidbhutta22-Feb-06 3:50 
AnswerRe: Having Scrollbars to MDI form? Pin
Judah Gabriel Himango22-Feb-06 7:13
sponsorJudah Gabriel Himango22-Feb-06 7:13 
QuestionSave with date format Pin
mostafa_h22-Feb-06 3:29
mostafa_h22-Feb-06 3:29 
AnswerRe: Save with date format Pin
Judah Gabriel Himango22-Feb-06 4:03
sponsorJudah Gabriel Himango22-Feb-06 4:03 
GeneralRe: Save with date format Pin
mostafa_h22-Feb-06 4:45
mostafa_h22-Feb-06 4:45 
GeneralRe: Save with date format Pin
Judah Gabriel Himango22-Feb-06 4:48
sponsorJudah Gabriel Himango22-Feb-06 4:48 
GeneralRe: Save with date format Pin
mostafa_h22-Feb-06 6:24
mostafa_h22-Feb-06 6:24 
AnswerRe: Save with date format Pin
Le centriste22-Feb-06 6:28
Le centriste22-Feb-06 6:28 
GeneralRe: Save with date format Pin
mostafa_h22-Feb-06 7:25
mostafa_h22-Feb-06 7:25 
GeneralRe: Save with date format Pin
Le centriste22-Feb-06 7:26
Le centriste22-Feb-06 7:26 
GeneralRe: Save with date format Pin
mostafa_h22-Feb-06 11:12
mostafa_h22-Feb-06 11:12 
QuestionThreading Pin
Areff22-Feb-06 3:27
Areff22-Feb-06 3:27 
AnswerRe: Threading Pin
Judah Gabriel Himango22-Feb-06 3:57
sponsorJudah Gabriel Himango22-Feb-06 3:57 
AnswerRe: Threading Pin
StyleGuide22-Feb-06 4:08
StyleGuide22-Feb-06 4:08 
AnswerRe: Threading Pin
StyleGuide22-Feb-06 4:09
StyleGuide22-Feb-06 4:09 
GeneralRe: Threading Pin
Areff22-Feb-06 23:04
Areff22-Feb-06 23:04 
QuestionSearch In File Pin
Areff22-Feb-06 3:17
Areff22-Feb-06 3:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.