Large numeric string literals coerced to integers


#1

Large numeric values are difficult to assign to strings due to intermediary coercions, I have not been able to find a way to properly represent a long numeric string literal. Consider representing a phone number, 5551234567, as a string.

5551234567 »»» (integer) 1256267271
'5551234567'»»» (integer) 1256267271

The string is converted to an integer but the number is too large to represent as an integer. Decimals fare better:

5551234567. »»» (decimal) 5551234567
'5551234567.' »»» (decimal) 5551234567

This looks good, but when decimals are coerced to strings the number is transformed to E notation:

5551234567. + '' »»» (string) 5.551234567E9

The only types of solutions I’ve found are clumsy and require an expression:

sprintf('%.0f', 5551234567.)
string('555') + string('1234567')
replace('x5551234567', 'x', '')

Is there any way to make string literals, especially when defined in expressions with explicit quotes, not coerce as greedily?


#2

Instead of integer, use longs - am I not exposing longs? Or perhaps I should make all longs 64bit


String Containing all Numeric Values Misbehaving [large number as string literal overflows to negative integer]
#3

I think part of the problem here is that I can’t tell if the value is stored incorrectly, displayed incorrectly, or both. I’m not technically “using integers” in the original case, just trying to get a value into a string where the value may happen to be a long.

Here is a piston that attempts to get this value into a long and then log that same value. It appears that I can set the value with a double or with a string but I don’t know of a literal form for longs.

+325ms ║1256267271
+338ms ║1256267271

+371ms ║5551234567
+384ms ║5551234567

+425ms ║5551234567
+438ms ║5551234567

I encountered this while working on a notification suite to publish in the Examples, just looking for a fairly easy way to let people specify a phone number. Maybe I need to require punctuation (e.g. ‘555-123-4567’) then strip it out with a regex.