我想让宏中的所有数字都显示为点而不是昏迷
例如此显示“0,03”但我想要“0.03”:
Dim MyNumber As Single
MyNumber = 0.03
MsgBox (MyNumber)
我已经尝试了一组,它的代码无法正常工作:
这仍然显示昏迷:
Application.DecimalSeparator = "."
这仍然显示昏迷并且不适用于整个宏
MyNumber = Format(MyNumber, "##0.00")
这显示点而不是昏迷,但不适用于整个宏
MsgBox (Replace(MyNumber, ",", "."))
谢谢!
作为第一步,必须声明来自 Kernel32 动态链接库的三个函数:
Private Declare Function GetUserDefaultLCID% Lib "kernel32" ()
Private Declare Function GetLocaleInfoA Lib "kernel32" (ByVal Locale As Long, ByVal LCType As Long, ByVal lpLCData As String, ByVal cchData As Long) As Long
Private Declare Function SetLocaleInfoA Lib "kernel32" ( ByVal Locale As Long, ByVal LCType As Long, ByVal lpLCData As String) As Boolean
小数的本地类型值为 14(有些人喜欢写 &HE - 十六进制 E -)
然后程序必须是这样的:
' record the settings in the variable LocalSettingsDecimal
Dim LocalSettingsDecimal As String
Dim Buffer As String
Buffer = String(256, 0)
Dim le As Integer
le = GetLocaleInfoA(GetUserDefaultLCID(), 14, Buffer, Len(Buffer))
LocalSettingsDecimal = Left(Buffer, le - 1)
' force decimal settings to '.'
Call SetLocaleInfoA(GetUserDefaultLCID(), 14, ".")
' body
Dim MyNumber As Single
MyNumber = 0.03
MsgBox (MyNumber)
' set back the decimal settings
Call SetLocaleInfoA(GetUserDefaultLCID(), 14, LocalSettingsDecimal)
请注意,不幸的是,如果程序主体失败,则不会恢复设置……但这仍然可以解决问题
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句