Words2Nums(3)

πŸ¦‹ Lingua::EN::Words2Nums β€” Words2Nums(3) πŸ¦‹

okay bestie, welcome to the User Contributed Perl Documentation page for Lingua::EN::Words2Nums β€” manual name Words2Nums(3) πŸ’…. This one is lowkey iconic: it takes English text and turns it into numbers, and it’s giving β€œmath but make it text” ✨.


πŸ’– NAME πŸ’–

Lingua::EN::Words2Nums β€” convert English text to numbers πŸ’–

🌸 SYNOPSIS 🌸

use Lingua::EN::Words2Nums;
$num=words2nums("two thousand and one");
$num=words2nums("twenty-second");
$num=words2nums("15 billion, 6 million, and nintee");

🌈 DESCRIPTION 🌈

This module converts English text into numbers. It supports both ordinal and cardinal numbers, negative numbers, and very large numbers. Periodt. πŸ’…

The main subroutine, which is exported by default, is words2nums(). Feed it a string and it will attempt to convert it into a number. If it succeeds, the number will be returned. If it fails, it returns undef β€” no cap, that’s the deal 😭.

πŸŽ€ VARIABLES πŸŽ€

There are a number of variables that can be used to tweak the behavior of this module. For example, debugging can be enabled by setting $Lingua::EN::Words2Nums::debug=1 πŸ‘€. These are your lil’ knobs, bestie:

  • $Lingua::EN::Words2Nums::debug β€” Default: 0. If set to a true value, outputs on standard error some useful messages if parsing fails for some reason. So when parsing is doing a whole mystery era, this tells you what’s up πŸ”.
  • $Lingua::EN::Words2Nums::billion β€” Default: 10 ** 9. This is the number that will be returned for "one billion". It defaults to the American version; the English will want to set it to 10 ** 12. Setting this number automatically changes all the larger numbers (trillion, quadrillion, etc) to match. Big-number behavior? Automatically upgraded πŸ’«.

🧚 NOTES 🧚

vibe check on the edge cases:

  • It does not understand decimals or fractions, yet. 😭 That’s the whole note; don’t come for me.
  • Scores are supported, eg: "four score and ten". So are dozens. So is a baker’s dozen. And a gross. Math with range, honestly πŸ’―.
  • Various mispellings of numbers are understood. 🫢 It’s forgiving like that.
  • While it handles googol correctly, googolplex is too large to fit in perl's standard scalar type, and "inf" will be returned. πŸ’€ That’s the limit, bestie.

πŸ‘‘ AUTHOR πŸ‘‘

Copyright 2001-2003 Joey Hess <joey@kitenet.net> πŸ’Œ

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. 🫢

mwah πŸ’‹ β€” this page’s source/version is perl v5.42.0, its date is 2014-12-02, and the manual is Words2Nums(3). Byeeee ✨

πŸ“¦ where this page comes from