Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Why doesn reading floating point numbers work when using wxWidgets?

0
Posted

Why doesn reading floating point numbers work when using wxWidgets?

0

If your program reads the floating point numbers in the format 123.45 from a file, it may suddenly start returning just 123 instead of the correct value on some systems — which is all the more mysterious as the same code in a standalone program works just fine. The explanation is that GTK+ changes the current locale on program startup. If the decimal point character in the current locale is not the period (for example, it is comma in the French locale), all the standard C functions won’t recognize the numbers such as above as floating point ones any more. The solution is to either use your own function for reading the floating point numbers (probably the best one) or to call setlocale(LC_NUMERIC, “C”) before reading from file and restore the old locale back afterwards if needed.

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123