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

前端 未结 1 1773
不思量自难忘°
不思量自难忘° 2021-01-24 03:35

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 ho

1条回答
  •  别那么骄傲
    2021-01-24 04:01

    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

    0 讨论(0)
提交回复
热议问题