Course of Raku / Advanced / More about built-in types / Integers / Exercises / How many digits

Solution: How many digits

Here is a possible solution to the task.

Code

say (2 ** 1000).chars;

🦋 You can find the source code in the file big-factorial.raku.

Output

302

Comments

  1. 2 ** 1000 is computed exactly: Raku does not round it or overflow, because integers have arbitrary precision.

  2. chars is normally a string method, but calling it on an integer first turns the number into its decimal text and then counts the characters. As there are neither minus sign nor decimal point here, that character count is exactly the number of digits — 302.

Course navigation

How many digits   |   Hex to decimal