|
-
Jul 26th, 2006, 06:58 AM
#1
Thread Starter
Lively Member
Very Easy Question on Decimal Numbers
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
-
Jul 26th, 2006, 07:34 AM
#2
Re: Very Easy Question on Decimal Numbers
use the math namespace to round the value
VB Code:
math.Round(74474.3498393431, 3)
Will give you 3 numbers after the decimal
-
Jul 26th, 2006, 07:49 AM
#3
Addicted Member
Re: Very Easy Question on Decimal Numbers
Using Format
VB Code:
Format(74474.3498393431, "####.###")
gives 74474.35 (rounds)
to assure 3 places always
VB Code:
Format(74474.3498393431, "####.000")
gives 74474.350
-
Jul 26th, 2006, 07:51 AM
#4
Thread Starter
Lively Member
Re: Very Easy Question on Decimal Numbers
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?
-
Jul 26th, 2006, 07:57 AM
#5
Addicted Member
Re: Very Easy Question on Decimal Numbers
Either of the methods above:
VB Code:
txtERL.Text = math.Round(objLogic.dblERLCalc.ToString(),3)
or
VB Code:
txtERL.Text = Format(objLogic.dblERLCalc,"####.000")
-
Jul 26th, 2006, 08:17 AM
#6
Re: Very Easy Question on Decimal Numbers
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
-
Jul 26th, 2006, 08:45 AM
#7
Thread Starter
Lively Member
Re: Very Easy Question on Decimal Numbers
Worked perfectly. Thanks all!
-
Jul 26th, 2006, 05:02 PM
#8
Re: Very Easy Question on Decimal Numbers
Don't forget to resolve your thread from the Thread Tools menu.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|