|option: convertible||If you want to test if the string <B>couldB> be a number if it were run through to_number() then use the convertible option.|
Converts a string to a number by removing commas and spaces. If the string cant be converted, returns undef. Some examples:
to_number( 3 ); # returns 3 to_number( 3,000 ); # returns 3000 to_number(whatever); # returns undef
option: always_number If the string cannot be converted to a number, return 0 instead of undef. For example, this call:
Converts a number to a string representing the same number but with commas
commafie(2000); # 2,000 commafie(-2000); # -1,000 commafie(2000.33); # 2,000.33 commafie(100); # 100
The sep option lets you set what to use as a separator instead of a comma. For example, if you want to : instead of , you would do that like this:
which would give you this:
Prepends zeroes to the number to make it a specified length. The first param is the number, the second is the target length. If the length of the number is equal to or longer than the given length then nothing is changed.
zero_pad(2, 3); # 002 zero_pad(2, 10); # 0000000002 zero_pad(444, 2); # 444
Given lower and upper bounds, returns a random number greater than or equal to the lower bound and less than or equal to the upper. Works only on integers.
rand_in_range(3, 10); # a random number from 3 to 10, inclusive rand_in_range(-1, 10); # a random number from -1 to 10, inclusive
is_even returns true if the number is even. is_odd returns true if the number is odd. Nonnumbers and decimals return undef.
Here are a few other modules available on CPAN that do many of the same things as Number::Misc:
Copyright (c) 2012 by Miko OSullivan. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. This software comes with <B>NO WARRANTYB> of any kind.
Miko OSullivan firstname.lastname@example.org
Version 1.0 July, 2012 Initial release. Version 1.1 April 25, 2014 Fixed problem in META.yml. Version 1.2 January 2, 2015 Fixed issues in tests. Added sep option to commafie.
|perl v5.20.3||NUMBER::MISC (3)||2015-01-02|