格式化百分比/小数未显示正确的值

问题描述 投票:0回答:1

我正在尝试以百分比形式显示经过时间的进度,但是当达到[[几乎最终目标(例如0.98或0.99)时,它显示的是100%。

这里是代码。

main.Shapes("shape1").DrawingObject.Text = Format(result, "(0%)")

result从0降到1,00的位置。

如果result还不是100%,有没有不显示100%的技巧?

vba format
1个回答
0
投票
只需给它提供尽可能多的小数位,而无需四舍五入。

result = 0.99999 fmtPattern = "0%" If result >= 0 And result < 1 Then decPlaces = Len(CStr(result)) - 4 If decPlaces > 0 Then fmtPattern = "0." & String(decPlaces, "0") & "%" End If End If main.Shapes("shape1").DrawingObject.Text = Format(result, "(" & fmtPattern & ")")

© www.soinside.com 2019 - 2024. All rights reserved.