Converting a Double like ,254 with Format$ to 0,254

Hello,

I think my issue is simple. I have some doubles.

As long as the doubles >=1 my Print statements

work, but values <1 are printed like ,254.

I need 0,254. I played a little with Format$, but I do not get it.

Some example show the pattern.

0,254

175,698

100

1760,565

My Testcode

Sub Initialize

Dim dblA As Double

Dim dblB As Double



dblA = 256/1000

dblB = 175698/1000

Print "dblA " & dblA

Print "dblB "  & dblB 





'/ style = 0,256 or 175,698

Print "dblA style"  & Format$(dblA,"#,###")

Print "dblB style"  & Format$(dblB,"#,###")

Final:

Exit Sub

Errorhandling:

Messagebox "Bitte wenden Sie sich an Ihren Administrator: " + Chr(13) +_

logerror, 16, "Fehler"

Resume Final

End Sub

If don’t get it to work I will try something like

“0” + cstr(dblA), but I thinkl there must be better solution…

Thank you

Regards

-i

Subject: Converting a Double like ,254 with Format$ to 0,254

Wouldn’t the simplest solution be to test for < zero?

Like this:

If (dblA < 0) Then

Print “dblA = 0” & Format$(dblA, ",###)

End If

Alternatively, you could do the format first and the check after:

strResult = Format$(dblA, "#,###)

If (Left$(strResult, 1) = “,”) Then strResult = “0” & strResult

Subject: RE: Converting a Double like ,254 with Format$ to 0,254

Ok, thank you. I will try it tommorow.

Currently I use

If dblA < 0 then

“0” + cstr(dbla)

Negative values are not possible.

Regards

-i

Subject: RE: Converting a Double like ,254 with Format$ to 0,254

B.t.w, have you tried this: Format$(dblA, “0,###”)