I'm working on modernizing Rosetta Code's infrastructure. Starting with communications. Please accept this time-limited open invite to RC's Slack.. --Michael Mol (talk) 20:59, 30 May 2020 (UTC)

# Talk:Getting the number of decimals

## Fractions? Trailing Zeros?

What exactly is meant by 'number' in the task description? Fractions are numbers. 1/4 is a fraction whose decimal expansion contains two decimal places. 1/3 is a fraction whose decimal expansion contains an infinite number of decimal places. Are we not meant to handle fractions, even if our language features them as first-class literals?

Can we also get some clarity regarding trailing zeros? Most languages feature numeric types that do not retain trailing zeros. I see that some entries are using strings for these cases instead. Is that intended by the task?

Floating point numbers may also be problematic as mentioned in the Raku entry. By the way, how many decimal places does fp-zero have? How about fp-infinity?

Should we also handle other numeric types with decimal points? Many languages feature some sort of 'BigDecimal' type and complex number type, for example.

It would be nice if the task description could elaborate on some of the above concerns. A restriction of the scope of the task (beyond merely 'numbers'), as well as having an actual task to solve beyond a couple cryptic inputs and outputs would be much appreciated as well. --Chunes (talk) 12:22, 13 August 2020 (UTC)

The description doesn't even exert itself unduly on the question of whether the input value is a String or something else :-)
What is the expected result when the input is `pi` ?
0 ? (we read `pi` as a string ?)
Infinity ? (we read `pi` as bound to a mathematically defined value) ?
Something else ? (we read `pi` as a system constant, bound to some unspecified member of a zoo of types that might include creatures like f32, f64, i32, i64, i128, or perhaps even their cousins u32, u64, u128, each of which would contain expansions of pi to different digit lengths - most of them zero) ? Hout (talk) 09:10, 14 August 2020 (UTC)
To concretise a little, the initial Python suggestion just errors when the given number is math.e, math.pi, or math.tau, all of which have Python type `float` and are quite hard not to think of as 'numbers', in terms of the task title. Hout (talk) 09:22, 14 August 2020 (UTC)

### Strings

The "number of decimals" I took as being a function of how a number is represented. It is either stated implicitly or implied by its string representation. 1.0, 1.00, 1.000, and 1.0000 would all have the same floating point value in Python, but when read can suggest differing levels of precision used in calculating a value, (at least in Physics and Engineering when they pay attention to significant digits). --Paddy3118 (talk) 08:12, 16 August 2020 (UTC)

Normally I would agree, but the reference implementation (Ring) does no string parsing whatsoever as far as I can tell. --Chunes (talk) 08:45, 16 August 2020 (UTC)
And if this were really intended as a function over a string (the reference implementation and task description both indicate otherwise), it would be far too trivial to be worth promoting to task status. Hout (talk) 08:54, 16 August 2020 (UTC)

Just trying to bring some meaning to an obscure description. What other way is there to distinguish 12.3450 of the description from 12.345 or 12.34500 in Python (and a lot of other languages)? --Paddy3118 (talk) 09:31, 16 August 2020 (UTC)

It's very curious that the Ring entry doesn't bother to show the examples from the task description. Does it even work? --Chunes (talk) 09:41, 16 August 2020 (UTC)
I've invited the original author to join in the discusions... --Paddy3118 (talk) 09:48, 16 August 2020 (UTC)

Hmm, still no input from the original author. The task description together with its initial implementation from the originating author are imprecise. This needs changing or abandoning. --Paddy3118 (talk) 15:42, 23 August 2020 (UTC)

I think it's too early to throw the baby out with the bath water.     -- Gerard Schildberger (talk) 23:57, 23 August 2020 (UTC)

I had a little uneasiness when reading   get the number of decimals.       I presumed several things.       --- Yeah, yeah,   I know what presumption can do and what it can lead to --- a very steep and fast decent into chaos and self-fulfilling definitions.   But, I trudged on.

By   decimals,   I presumed the task's author meant decimal digits,   that would presume   (to me)   that the number is expressed in base ten,   or is to be converted to base ten,   depending on what programmers are assuming whatever flavor of expressing numbers that their (favorite) computer programming language(s) assumes/uses such animals.

By all the other programming examples,   included the task's preamble,   I also understood   (and observed)   that the   number of decimals   implied that it meant the   number of decimals   (decimal digits)     past the decimal point       (if there is a decimal point).

If there's no decimal point,   then define/assume that the number of decimals   (past the decimal point)   is zero.

Another   (perhaps more descriptive)   use of the phrase   decimal digits   (past the decimal point)   would be   fractional digits.

I further assumed that   if   a number was expressed in exponential format,   the number should/would be converted to a number without exponentiation,   and then  that  number would be then examined.

I took the word   get   to mean   obtain,   find,   or   determine,   and then, presumably,   display/show the results.     (With the usual caveat:   here, on this page.)

After all, if one   gets   (obtains)   the number of decimals in a given number,   then what?   Display them?   Everybody   (so far)   has seemed to just display the   number   of decimal (digits) found   that are past the decimal point.

I understand that number of computer programming language's internal representations of decimal numbers with fractional digits don't have a concept of superfluous decimal zeros,   unless the decimal number is, for instance, enclosed in quotes and/or by some other notation(s).     -- Gerard Schildberger (talk) 23:57, 23 August 2020 (UTC)

Hi Gerard, The task, as you demonstrate, is not specific enough. Maybe there is some standard we could re-write the task to more closely adhere to, as others have interpretations that work for them, but are different. --Paddy3118 (talk) 09:42, 24 August 2020 (UTC)