VBA双逗号,而不是点的字符串 [英] VBA Double as String with comma and not point
问题描述
我正在寻找将double转换为字符串的解决方案,但字符串在小数点之前应该有一个逗号,而不是一个点。
One一半应该看起来像这样1,5(德国表示法)。
感谢您的帮助!!
将0.5这样的double转换为一个字符串,看看你最终结束了什么。如果你以 0,5
结尾,那么你是在德语(等)区域设置,你不需要做任何其他事情。
如果以 0.5
结尾,那么您知道需要进行转换。然后你只需要遍历你的字符串,用逗号代替点,反之亦然(反之亦然,如果你的字符串有成千上万的分隔符,这一点很重要)。您可以使用替换
。
I am searching for a solution to convert a double to a string, but the string should have a comma before the decimal place, not a point.
"One and a half" should look that way 1,5 (german notation).
Thanks for your help!!
Unfortunately in VBA, you can't easily write locale-independent code. That is, you can't specify a locale when you take a CStr
cast.
One work around is to convert a double like 0.5 to a string and see what you end up with. If you end up with 0,5
then you're in German (etc.) locale, and you don't need to do anything else.
If you end up with 0.5
then you know you need to make a conversion. Then you just need to traverse your string, replacing dots with commas and vice versa (the vice versa bit is important in case your string has thousands delimiters). You can use Replace
for that.
这篇关于VBA双逗号,而不是点的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!