Hi there,
From my program output i get a number like:
74474.3498393431
I want to show the first three digits after the dot. How can I do it please?
Thank you.
WebServant
Printable View
Hi there,
From my program output i get a number like:
74474.3498393431
I want to show the first three digits after the dot. How can I do it please?
Thank you.
WebServant
use the math namespace to round the value
VB Code:
math.Round(74474.3498393431, 3)
Will give you 3 numbers after the decimal
Using Format
to assure 3 places alwaysVB Code:
Format(74474.3498393431, "####.###") gives 74474.35 (rounds)
VB Code:
Format(74474.3498393431, "####.000") gives 74474.350
i have this:
ERLCalc = 0.0
R = DCV
For i = 0 To tblCustomData.Rows.Count - 1
If tblCustomData.Rows(i)("CompleteTrax") <> 1 Then
If (tblCustomData.Rows(i)("CompleteTrax")) <> 99999 Then
LF = (30.0 - tblCustomData.Rows(i)("CompleteTrax") - 1.0) / 30.0
DF = Math.Pow(1.0 / (1.0 + R), tblCustomData.Rows(i)("CompleteTrax") - 1.0)
Else
LF = (1.0 / 30.0)
DF = Math.Pow(1.0 / (1.0 + R), 29.0)
End If
ERLCalc = ERLCalc + tblCustomData.Rows(i)("Length") * DF * LF
End If
Next
Return ERLCalc
Then this:
txtERL.Text = objLogic.dblERLCalc.ToString()
How can Iround it please?
Either of the methods above:
orVB Code:
txtERL.Text = math.Round(objLogic.dblERLCalc.ToString(),3)
VB Code:
txtERL.Text = Format(objLogic.dblERLCalc,"####.000")
If you want to actually change the value of the number then use Math.Round. If you want to leave the actual number unaffected but display a string representation then use ToString("f3"), which means a fixed-point number with three decimal places. If you want thousand separators then use "n3" instead.
Numeric Format Strings
Worked perfectly. Thanks all!
Don't forget to resolve your thread from the Thread Tools menu.