Search code examples
luacygwin

Decimal number format and region coding


I have lua program, that loads data from string. I need to convert those data to double, using tonumber. Problem is, that under cygwin in Windows 7, I got nil, if number contains . insetad of ,. How to solve this ?

n = tonumber("7.5") -> gives nil
n = tonumber("7,5") -> gives 7.5

Solution

  • Try this:

    old = os.setlocale("C")
    n = tonumber("7.5")
    os.setlocale(old)