# Talk:Getting the number of decimal places

## 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)

- The description doesn't even exert itself unduly on the question of whether the input value is a

### 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)

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)

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)

## wording of the task

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)

## C/C++ marked incorrect

I assume it would be fair to say that the output of findNumOfDec() is correct, it is just that the display of x in test() is lacking? --Petelomax (talk) 13:02, 20 March 2023 (UTC)

- The task description gives 2 examples, one of which is " for num = 12.3450 decimals = 4" so for 12.0 and 12.345000 how many decimals do you think should be reported? How does this compare with the C output?--Nigel Galloway (talk) 15:40, 20 March 2023 (UTC)

- Oh yes indeed, by that definition I'd have to say the FreeBASIC, Haskell, Java, Kotlin, Ring, RPL (probably), Sidef entries are all equally "wrong". Personally I want to say that 12.3450 should have 3 decimal places, even though my own entry shows 4 for "12.3450", but in reality 12.345 is held as ~12.3450000000000006 in a 64-bit IEE754 float, and as ~12.34500000000000000024 in an 80-bit float, so that would be 16 and 20 decimals, at least in some "sense". Stupid task. Anyway, you (by which I mean Peak) either have to be consistent and badger everyone, or no-one, or better yet fix the stupid task description (after discussing it here first). --Petelomax (talk) 16:08, 20 March 2023 (UTC)