Number::FormatEng - Format a number using engineering notation
This document refers to Number::FormatEng version 0.03.
use Number::FormatEng qw(:all); print format_eng(1234); # prints 1.234e3 print format_pref(-0.035); # prints -35m unformat_pref('1.23T'); # returns 1.23e+12
Format a number for printing using engineering notation. Engineering notation is similar to scientific notation except that the power of ten must be a multiple of three. Alternately, the number can be formatted using an International System of Units (SI) prefix representing a factor of a thousand.
Format a numeric value using engineering notation. This function returns a string whose exponent is a multiple of 3. Here are some examples:
format_eng(1234); # returns 1.234e3 format_eng(-0.03); # returns -30e-3 format_eng(7.8e7); # returns 78e6
Since floating-point arithmetic is performed, rounding may occur.
Format a numeric value using engineering notation. This function returns a string using one of the following SI prefixes (representing a power of a thousand):
m u n p f a z y k M G T P E Z Y
Notice that lower-case u is used instead of the Greek letter Mu.
u
If the number is beyond the prefix ranges (y and Y), then format_pref returns the same formatted string as format_eng. In other words, it does not use an SI prefix.
format_pref
format_eng
Here are some examples:
format_pref(1234); # returns 1.234k format_pref(-0.0004); # returns -400u format_pref(1.27e13); # returns 12.7T format_pref(7.5e60); # returns 7.5e60
Convert a string formatted using format_pref into a numeric value. Here are some examples:
unformat_pref('1.23T'); # returns 1.23e+12 unformat_pref('-400u'); # returns -4e-4 unformat_pref(37.5); # returns 37.5
By default, if the exponent is zero, e0 is not displayed by format_eng. To explicitly display e0, use the use_e_zero method. Use the no_e_zero method to return to the default behavior.
e0
use_e_zero
no_e_zero
format_eng(55); # returns 55 Number::FormatEng::use_e_zero(); format_eng(55); # now returns 55e0 Number::FormatEng::no_e_zero(); format_eng(55); # back to 55
Nothing is exported by default. Functions may be exported individually, or all functions may be exported at once, using the special tag :all.
:all
Error conditions cause the program to die using croak from the Carp Core module.
croak
There are no known bugs in this module.
Refer to the following website:
http://en.wikipedia.org/wiki/Engineering_notation
Gene Sullivan (gsullivan@cpan.org)
Influenced by the following PerlMonks: BrowserUk, GrandFather and repellent.
Copyright (c) 2009 Gene Sullivan. All rights reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.
To install Number::FormatEng, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Number::FormatEng
CPAN shell
perl -MCPAN -e shell install Number::FormatEng
For more information on module installation, please visit the detailed CPAN module installation guide.