txt: ## base.md
  base
  
  Combined from primary sources listed below.
  
  # [In role Real](#___top "go to top of document")[§](#(role_Real)_method_base "direct link")
  
  See primary documentation
  [in context](/type/Real#method_base)
  for **method base**.
  
  ```raku
  method base(Real:D: Int:D $base where 2..36, $digits? --> Str:D)
  ```
  
  Converts the number to a string, using `$base` as base. For `$base` larger than ten, capital Latin letters are used.
  
  ```raku
  255.base(16);            # 'FF'
  ```
  
  The optional `$digits` argument asks for that many digits of fraction (which may not be negative). If omitted, a reasonable default is chosen based on type. For Int this default is 0. For [`Num`](/type/Num), the default is 8. For [`Rational`](/type/Rational), the number of places is scaled to the size of the denominator, with a minimum of 6.
  
  A special value of [`Whatever`](/type/Whatever) (`*`) can be given as `$digits`, which functions the same as when `$digits` is not specified for all `Real` types except the [`Rational`](/type/Rational)s. For [`Rational`](/type/Rational)s, the [`Whatever`](/type/Whatever) indicates that you wish all of the possible digits of the fractional part, but use caution: since there's no detection of repeating fractional parts (the algorithm will eventually stop after generating 2\*\*63 digits).
  
  The final digit produced is always rounded.
  
  ```raku
  say pi.base(10, 3);      # OUTPUT: «3.142␤»
  say (1/128).base(10, *); # OUTPUT: «0.0078125␤»
  say (1/100).base(10, *); # OUTPUT: «0.01␤»
  say (1/3)  .base(10, *); # WRONG: endlessly repeating fractional part
  ```
  
  For reverse operation, see [`parse-base`](/routine/parse-base)
  