Search code examples
cprintfradix

snprintf : simple way to force . as radix?


My program was not behaving correctly on one machine so I started to hunt for the bug, and I discovered that on that machine, snprintf uses a comma (,), not a . (dot) as 99% of other computers (at least in my experience).

Shouldn't this be standardized?

I am using a library that assumes that the radix is a . (dot) and so it does not work properly with a comma.

So my question is, is there a simple way to force the dot as the radix character? I know I could just search & replace the comma by a dot manually, but surely there is a cleaner way.


Solution

  • You should be able to change your locale-setting using the setlocale-function to make snprintf use a dot. Try setting it to "POSIX" or "C". (setlocale(LC_ALL, "POSIX")