This Is A Custom Widget

This Sliding Bar can be switched on or off in theme options, and can take any widget you throw at it or even fill it with your custom HTML Code. Its perfect for grabbing the attention of your viewers. Choose between 1, 2, 3 or 4 columns, set the background color, widget divider color, activate transparency, a top border or fully disable it on desktop and mobile.

This Is A Custom Widget

This Sliding Bar can be switched on or off in theme options, and can take any widget you throw at it or even fill it with your custom HTML Code. Its perfect for grabbing the attention of your viewers. Choose between 1, 2, 3 or 4 columns, set the background color, widget divider color, activate transparency, a top border or fully disable it on desktop and mobile.

is_numeric

The is_numeric() function allows you to check if a particular variable is a numeric string. Numeric strings can consist of a sign, any number of digits, a decimal part and an exponential part.

PHP

$my_string = '+1.998';
var_dump( is_numeric($string1) );
// => true

Ruby

 
def is_numeric?(num)
    true if Float(num) rescue false;
end

my_string = '+1.985';
puts is_numeric?(my_string);
# => true
By | 2009-11-07T11:33:46+00:00 August 8th, 2009|Categories: PHP, Ruby|Tags: , , , |3 Comments

About the Author:

3 Comments

  1. jef November 7, 2009 at 9:06 am

    ruby -v
    ruby 1.8.7 (2008-08-11 patchlevel 72) [i686-linux]

    >> “1a”.is_a?(Numeric)
    => false
    >> “1”.is_a?(Numeric)
    => false

    this info is not correct, do we have to define our own function. please test your code before publishing it!!

  2. RubyLove November 7, 2009 at 11:31 am

    @jef

    Your right, there are some situations where the above code doesnt work – I’ve updated it with a slightly more robust function:


    def is_numeric?(num)
    true if Float(num) rescue false;
    end

    my_string = '1';
    puts is_numeric?(my_string);

  3. Mike DiGioia April 20, 2010 at 6:06 pm

    class String
    def is_numeric?
    self.strip =~ /^(-|\+|)[0-9]*(\.[0-9]+)?$/
    end
    end

    p ‘123’.is_numeric?

Comments are closed.