在 Excel 2003 中将 unicode 分数字符(粗俗分数)转换为小数
我正在尝试将以下文本转换为 excel 2003 中的十进制数字:
“93⅛”
输出应该是:93.125
我已经通过使用 VBA 中的替换函数将其与 1/4、1/2、3/4 一起使用: 例如,这有效:
cur_cell = Replace(cur_cell, "½", " 1/2")
但是,VBA 编辑器不支持 ⅛ 和系列字符。它们显示为??。相反,我尝试直接替换 unicode 值:
cur_cell = Replace(cur_cell, " & ChrW$(&H215B) & ", " 1/8")
但这不起作用。
有没有一种好的方法可以将这些字符串转换为我可以使用的数字?
I'm trying to convert the following text to a decimal number in excel 2003:
"93⅛"
The output should be: 93.125
I've gotten this to work with ¼, ½, ¾ by using the Replace function in VBA:
For example, this works:
cur_cell = Replace(cur_cell, "½", " 1/2")
However, the ⅛ and family characters are not supported in the VBA editor. They display as ??. Instead, I tried to replace the unicode value directly:
cur_cell = Replace(cur_cell, " & ChrW$(&H215B) & ", " 1/8")
But this doesn't work.
Is there a good way to convert these strings to numbers that I can use?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正确的语法是:
您的示例是这样的:将由空格、与号、空格[等]组成的字符串替换为
1/8
。显然这不是你想做的!我实际上建议:
绕过 Excel 的自动替换分数。我只是不喜欢依赖那种自动的东西。为什么不直接把它写成十进制数呢?另外,我喜欢明确引用单元格的
.Value
属性,而不是依赖它作为默认属性。The correct syntax is:
Your example was saying: replace the string consisting of a space, an ampersand, a space [etc.] with
1/8
. Clearly that's not what you want to do!I'd actually recommend:
to circumvent Excel's automatic replacement of fractions. I just don't like to rely on that kind of automatic stuff. Why not write it as a decimal number straight off? Also, I like explicitly refering to the cell's
.Value
property as opposed to relying on it being the default property.