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

女生的网名这么多〃 提交于 2019-12-04 05:01:54

问题


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 ...)

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


回答1:


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

(updated link 11-aug-2016)

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



来源:https://stackoverflow.com/questions/22709067/convert-decimal-separator-from-comma-to-dot-e-g-7-5-to-7-5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!