Inconsistent behaviour when converting strings to numbers
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Inconsistent behaviour when converting strings to numbers
- From: Marc Balmer <marc@...>
- Date: 2016年2月15日 12:27:14 +0100
When a string is converted to a number using coercion, it is converted to a floating point number, even if it does not contain a decimal point. When the tonumber() function is used, a string without decimal point is converted to an integer:
Lua 5.3.2 Copyright (C) 1994-2015 Lua.org, PUC-Rio
> a = 0
> a = 0 + '1'
> = a
1.0
> = tonumber('1')
1
Is this beviour intended? (and if yes, why?)