File Exchange

image thumbnail

Number to Myriad

version (3.57 KB) by Stephen Cobeldick
Convert a number to a string giving the value using Knuth's Myriad/Yllion naming scheme.


Updated 23 Sep 2017

View License

Convert a numeric scalar into a string giving the number value using Donald Knuth's Myriad (aka -Yllion) number naming scheme, e.g. 1024e6 -> 'Ten Myllion Twenty-Four Hundred Myriad', or '10;2400,0000' as digits.

str = num2myriad(num)
str = num2myriad(num,dgt)

The input numeric value is rounded and the output precision is defined to ensure the least-unexpected output: single=6 digits; double=15 digits; while int/uint values are parsed at their full precision. The function implements an efficient algorithm without using recursion, and with just one for-loop.

### Myriad System (aka -Yllion) ###

Donald Knuth's Myriad number naming system uses a logarithmic increase in group magnitudes for a much more efficient usage of the group names:

10^0 one
10^1 ten
10^2 hundred
10^4 myriad
10^8 myllion
10^16 byllion
10^32 tryllion
10^64 quadryllion
10^128 quintyllion
10^256 sextyllion

Knuth defined the pronunciation as "a myllion (pronounced mile-yun)".

Original Reference: "Supernatural Numbers" by Donald E. Knuth
(pp. 310-325 in The Mathematical Gardner, editor David A. Klarner, 1981)
Online References:

### Examples ###

ans = 'Zero'

ans = 'Ten Hundred Twenty-Four'

ans = 'Negative Three Myriad Twenty-Seven Hundred Sixty-Eight'
ans = '-3,2768'

ans = 'Ninety-Eight Myllion Seventy-Six Hundred Fifty-Four Myriad Thirty-Two Hundred Ten'
ans = '98;7654,3210'

ans = 'One Quadryllion'
ans = '1::0000,0000;0000,0000:0000,0000;0000,0000;;0000,0000;0000,0000:0000,0000;0000,0000'

num2myriad(1e303) % aka one centillion (short scale)
ans = 'Ten Hundred Myriad Myllion Tryllion Sextyllion'

Comments and Ratings (0)


* Correct zip file.

* Improve help.

* Edit blurb.

* Fix bug in myriad parsing (if >1 highest level multiplier).

* Replace tabs with four space characters.
* Improve index calculation.

* Add image

MATLAB Release Compatibility
Created with R2010b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Discover Live Editor

Create scripts with code, output, and formatted text in a single executable document.

Learn About Live Editor