Numeric n data type

The docs here says

Numeric n values are rational numbers with 38 decimal digits. The scale parameter n controls the number of digits after the decimal point, so for example,Numeric 10 values have 10 digits after the decimal point, andNumeric 20values have 20 digits after the decimal point. The value of n must be between 0 and 37 inclusive

The 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?

       amount: Numeric 37
       amount = 0.1234567890_1234567890_1234567890_1234567

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.

1 Like

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. decimal in this case just means that it’s a number between 0 and 9 but decimal digits takes 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.


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’!!

1 Like