【使用】Format 函数重新学习
作者:JiaJia 日期:2007-10-22
1、常规运用:(直接看代码)
Dim TestDateTime As Date = #1/27/2001 5:04:23 PM# Dim TestStr As String ' Returns current system time in the system-defined long time format. TestStr = Format(Now(), "Long Time") ' Returns current system date in the system-defined long date format. TestStr = Format(Now(), "Long Date") ' Also returns current system date in the system-defined long date ' format, using the single letter code for the format. TestStr = Format(Now(), "D") ' Returns the value of TestDateTime in user-defined date/time formats. ' Returns "5:4:23". TestStr = Format(TestDateTime, "h:m:s") ' Returns "05:04:23 PM". TestStr = Format(TestDateTime, "hh:mm:ss tt") ' Returns "Saturday, Jan 27 2001". TestStr = Format(TestDateTime, "dddd, MMM d yyyy") ' Returns "17:04:23". TestStr = Format(TestDateTime, "HH:mm:ss") ' Returns "23". TestStr = Format(23) ' User-defined numeric formats. ' Returns "5,459.40". TestStr = Format(5459.4, "##,##0.00") ' Returns "334.90". TestStr = Format(334.9, "###0.00") ' Returns "500.00%". TestStr = Format(5, "0.00%")
补充:
在日期Text控件中,显示金额时,都是100000 不便于判断是否对错,可以使用Fromat函数格式化显示
text1.text=fromat(text1.text,###,##0.00) 显示为100,000 .00 可以把真实的值存在.tag中
2、不同数值的不同格式
第一部分定义正值和零的格式,第二部分定义负值的格式。由于 Format 函数的 Style 参数采用字符串形式,因此在其两边加上引号。
Dim Style1 As String = "$#,##0;($#,##0)"
如果有几个分号,但分号之间没有任何内容,则缺少的部分使用正值的格式显示。例如,下列格式使用第一部分中的格式显示正值和负值,如果值为零,则显示 Zero。
Dim Style2 As String = "$#,##0;;\Z\e\r\o"
评论: 0 | 引用: 0 | 查看次数: -
发表评论