我想缩短粗略的篇幅。
text1.text = 2137.2198231578
从以上来看,只想显示头2位数位数。
Expected Output
text1.text = 2137.21
How to do this.
我想缩短粗略的篇幅。
text1.text = 2137.2198231578
从以上来看,只想显示头2位数位数。
Expected Output
text1.text = 2137.21
How to do this.
Format("2137.2198231578", "####.##")
在我注意到P0rter评论时,我即将张贴<代码>Format(。
Format(text1.text, "000.00")
I guess Int()
will round down for you.
自我使用VB6以来,已经多年了。
这一职能应当做你想要做的事情(在线评论应当解释正在发生的事情):
Private Function FormatDecimals(ByVal Number As Double, ByVal DecimalPlaces As Integer) As String
Dim NumberString As String
Dim DecimalLocation As Integer
Dim i As Integer
Dim LeftHandSide As String
Dim RightHandSide As String
convert the number to a string
NumberString = CStr(Number)
find the decimal point
DecimalLocation = InStr(1, NumberString, ".")
check to see if the decimal point was found
If DecimalLocation = 0 Then
return the number if no decimal places required
If DecimalPlaces = 0 Then
FormatDecimals = NumberString
Exit Function
End If
not a floating point number so add on the required number of zeros
NumberString = NumberString & "."
For i = 0 To DecimalPlaces
NumberString = NumberString & "0"
Next
FormatDecimals = NumberString
Exit Function
Else
decimal point found
split out the string based on the location of the decimal point
LeftHandSide = Mid(NumberString, 1, DecimalLocation - 1)
RightHandSide = Mid(NumberString, DecimalLocation + 1)
if we don t want any decimal places just return the left hand side
If DecimalPlaces = 0 Then
FormatDecimals = LeftHandSide
Exit Function
End If
make sure the right hand side if the required length
Do Until Len(RightHandSide) >= DecimalPlaces
RightHandSide = RightHandSide & "0"
Loop
strip off any extra didgits that we dont want
RightHandSide = Left(RightHandSide, DecimalPlaces)
return the new value
FormatDecimals = LeftHandSide & "." & RightHandSide
Exit Function
End If
End Function
使用:
Debug.Print FormatDecimals(2137.2198231578, 2) outputs 2137.21
看起来相当简单,但我必须在这里找不到一些微妙之处。 什么是:
Option Explicit
Private Function Fmt2Places(ByVal Value As Double) As String
Fmt2Places = Format$(Fix(Value * 100#) / 100#, "0.00")
End Function
Private Sub Form_Load()
Text1.Text = Fmt2Places(2137.2198231578)
End Sub
这还在当地发挥作用,因为小点特征是 com。
Win.ShellExecute 0, "open", "C:dirprogram.exe", "arguments", vbNullString, SW_SHOWNORMAL Win.ShellExecute 0, "open", "http://www.google.com", vbNullString, vbNullString, SW_SHOWNORMAL I want google....
I have a stored procedure in Sql Server 2005 with a varchar input parameter defined as: @Value varchar(24) = NULL in my VB6 application I try to set the parameter with an ADO function: Set ...
Using VB6 In a folder, i have n number of files, i want to delete a 0 kb files code Dim filename5 As String filename5 = Dir$(txtsourcedatabasefile & "*_*", vbDirectory) MsgBox filename5 Do ...
Using VB6 I have the text file with different sizes, so i want to delete the file where filesize = 0 kb. How to make a vb6 code for deleting the 0 kb files. Need vb6 code Help
I m using VB6 and I have a folder where I have n number of files. I want to change the file extension to .txt. I used the code below to change the extension of all .fin files to .txt. Dim filename1 ...
I m using Crystal Reports in my VB6 project, but I m facing error while loading the report in crystalreport1.action=1; Please give me some solution for this problem. It is showing the error as Error ...
When running my vb6 application I am getting error like, runtime error 53 : file not found: rscomclNoMsg.dll then i tried to register that dll from cmd line using regsvr32. Then I am getting ...
How to determine if a Transaction is active i.e. before issuing Begin Transaction I want to ensure that no previous transaction are open.. the platform is VB6, MS-SQL Server 2000 and ADO 2.8