vba 将小数点分隔符从“,”(逗号)转换为“.” (点)例如“7,5”到“7.5”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22709067/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 18:02:20  来源:igfitidea点击:

Convert decimal separator from ',' (comma) to '.' (dot) e.g. "7,5" to "7.5"

excelvbanumber-formatting

提问by przemo_li

Yes. I know. Those are localization settings...

是的。我知道。这些是本地化设置...

But I wont tell my client to change localization settings for just my app.

但我不会告诉我的客户只为我的应用程序更改本地化设置。

So how to convert those numbers? Or how to change number formatting for given range. (Need dots there, user may input comas or dots, or even numbers where commas just separate like 1,000,000.00 ...)

那么如何转换这些数字呢?或者如何更改给定范围的数字格式。(需要点在那里,用户可以输入逗号或点,甚至数字,其中逗号只是分开,如 1,000,000.00 ...)

EDIT: Circumvented whole issue by CStr(), and passing on the strings.

编辑:通过 CStr() 绕过整个问题,并传递字符串。

回答by Sam

If this is purely for display purposes then you can use custom format strings on the cells. Then your users can continue to use their localization settings that they are used to for inputting numbers. I think that changing localization settings would be a bad idea, as then your client may enter numbers incorrectly.

如果这纯粹是为了显示目的,那么您可以在单元格上使用自定义格式字符串。然后,您的用户可以继续使用他们习惯于输入数字的本地化设置。我认为更改本地化设置是一个坏主意,因为这样您的客户可能会错误地输入数字。

This is the general way of formatting numbers using custom format strings.

这是使用自定义格式字符串格式化数字的一般方法。

╔═════════════╦══════════════════════════╦═══════════════╗
║ To display  ║            As            ║ Use this code ║
╠═════════════╬══════════════════════════╬═══════════════╣
║ 1234.59     ║ 1234.6                   ║ ####.#        ║
║             ║                          ║               ║
║ 8.9         ║ 8.9                      ║ #.000         ║
║             ║                          ║               ║
║ 0.631       ║ 0.6                      ║ 0.#           ║
║             ║                          ║               ║
║ 12          ║ 12                       ║ #.0#          ║
║             ║                          ║               ║
║ 1234.568    ║ 1234.57                  ║ #.0#          ║
║             ║                          ║               ║
║ 44.398      ║   44.398                 ║ ???.???       ║
║ 102.65      ║ 102.65                   ║ ???.???       ║
║ 2.8         ║     2.8                  ║ ???.???       ║
║             ║ (with aligned decimals)  ║               ║
║             ║                          ║               ║
║ 5.25        ║ 5 1/4                    ║ # ???/???     ║
║ 5.3         ║ 5  3/10                  ║ # ???/???     ║
║             ║ (with aligned fractions) ║ # ???/???     ║
╚═════════════╩══════════════════════════╩═══════════════╝


And here is a link to the Microsoft information on regional format strings

这是指向 Microsoft 有关区域格式字符串的信息的链接

(updated link 11-aug-2016)

(更新链接 2016 年 8 月 11 日)

https://support.office.com/en-gb/article/Create-or-delete-a-custom-number-format-78f2a361-936b-4c03-8772-09fab54be7f4

https://support.office.com/en-gb/article/Create-or-delete-a-custom-number-format-78f2a361-936b-4c03-8772-09fab54be7f4