Numeric n data type
- Neelam_DwivediOP
The docs here says
Numeric n values are rational numbers with38decimal digits. The scale parameterncontrols the number of digits after the decimal point, so for example,Numeric 10values have 10 digits after the decimal point, andNumeric 20values have 20 digits after the decimal point. The value ofnmust be between0and37inclusiveThe first few lines above mean that the max is 38 digits after the decimal. The last sentence says n can be max 37.
The code below takes only 37. If I change it to 38, it doesn’t compile. So looks like the number 38 is incorrect. Can you please confirm?
let amount: Numeric 37 amount = 0.1234567890_1234567890_1234567890_1234567 - WallaceKelly 1
Hi, @Neelam_Dwivedi. I like attention to detail, so this question catches my attention. Thank you!
I wonder if the wording is correct. For example, when the docs start by saying “38 decimal digits” that may not imply what you said, “that the max is 38 digits after the decimal.” Perhaps there is always at least one digit to the left of the decimal point.
I experimented with this:
numeric_test = script do let big = 1234567890_1234567890_1234567890_12345678.0 : Numeric 0 let biggest = 9999999999_9999999999_9999999999_99999999.0 : Numeric 0 let small = 1.234567890_1234567890_1234567890_12345678 : Numeric 37 let smallest = 0.000000000_0000000000_0000000000_00000001 : Numeric 37 return ()After playing with the above and seeing what will compile and what will not compile, I’m leaning towards the docs being accurate.
- cocreature 3
Your confusion might come from
decimals. That is sometimes used to denote only the digits right of the decimal point.Here we are talking about
decimal digits.decimalin this case just means that it’s a number between 0 and 9 butdecimal digitstakes into account both the number left of the decimal point and right of the decimal point. So the docs are not saying that there are 38 decimals right of the decimal point but that a Numeric value has 38 digits in total and then the scale determines how many of those 38 are right of the decimal point while the others are left.The intro on wikipedia provides some more context on the terminology.
- Neelam_Dwivedi 1
Thanks @WallaceKelly! I didn’t consider that whatever is before the decimal is counted in those 38. The confusion is because of the choice of words… ‘decimal digits’ and ‘digits after the decimal’!!