12/4/2023 0 Comments Convert string to integer in perl![]() ![]() If the optional secondĪrgument $length is passed, to_string() will Other value, if the stringification operator has been overridden for the Such a value may be a memory address, or some $val is a reference, the string value of the To_string ¶ my $string = to_string($val) $bool = is_string(undef) # Returns false. My $bool = is_string('foo') # Returns true. All defined non-references are considered strings. To_float() will extract the first float it finds. If $val is a mixture of numbers and letters, Second argument sets the precision of the number. $bool = is_float(1.23e99) # Returns true. Returns true if $val is a float, and false To_decimal(), since this module cannot identify non-decimal realįuture. Note: Currently, this function is the equivalent of This implementation may change in theįuture. Is_decimal(), since this module cannot identify non-decimal real Note: This function is currently equivalent to Returns true if $val is a real number, and $dec = to_decimal('foo') # Returns undef. Letters, to_decimal() will extract the first decimal number it Optional second argument sets the precision of the number. $bool = is_decimal(1.23e99) # Returns false. $bool = is_decimal(-33.48) # Returns true. My $bool = is_decimal(10) # Returns true. ![]() Numbers may be preceded by a plus or minus sign. Returns true if $val is a decimal number,Īnd false if it is not. Is_decimal ¶ my $bool = is_decimal($val) Letters, to_int() will extract the first decimal number it finds and $val is a decimal number, it will be rounded to the Regular expression used to test for an integer in $count = to_count('foo') # Returns undef.įalse if it is not. $count = to_count(.22) # Returns undef (rounded down to 0). It finds and convert that number to a counting number. Numbers and letters, to_count() will extract the first decimal number That since 0 (zero) is not considered a counting number by this module, it Numbers will be rounded to the nearest counting number. Returns true if $val is a counting number $whole = to_whole('foo') # Returns undef. To_whole() will extract the first decimal number it finds and convert $val is a mixture of numbers and letters, ![]() Numbers will be rounded to the nearest whole. FUNCTIONS ¶ is_whole ¶ my $bool = is_whole($val) :to Exports all conversion functions: to_whole(), to_int(), :is Exports all validation functions: is_whole(), is_int(), :string Exports is_string() and to_string(). :float Exports is_float() and to_float(). :decimal Exports is_decimal() and to_decimal(). :count Exports is_count() and to_count(). Supported: :whole Exports is_whole() and to_whole(). No functions are exported by default, though each function may beĮxported explicitly (see "FUNCTIONS" below, for a list ofįunctions available for export). Where data types are more important than they typically are in Perl - e.g., This module exports a number of functions that are useful for $string = to_string($string) unless is_string($string) $float = to_float($float) unless is_float($float) $real = to_real($real) unless is_real($real) $decimal = to_decimal($decimal) unless is_decimal($decimal) $whole = to_whole($whole) unless is_whole($whole) Data::Types - Validate and convert data types. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |