File Exchange

image thumbnail

Number to Myriad

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


Updated 09 Jul 2020

View Version History

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

>> num2myriad(0)
ans = 'Zero'

>> num2myriad(1024)
ans = 'Ten Hundred Twenty-Four'

>> num2myriad(intmin('int16'))
ans = 'Negative Three Myriad Twenty-Seven Hundred Sixty-Eight'
>> num2myriad(intmin('int16'),true)
ans = '-3,2768'

>> num2myriad(9876543210)
ans = 'Ninety-Eight Myllion Seventy-Six Hundred Fifty-Four Myriad Thirty-Two Hundred Ten'
>> num2myriad(9876543210,true)
ans = '98;7654,3210'

>> num2myriad(1e64,false)
ans = 'One Quadryllion'
>> num2myriad(1e64,true)
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'

Cite As

Stephen Cobeldick (2021). Number to Myriad (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (0)

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

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!