I understand that when casting a string to a float, php will evaluate from left to right and stop at the first invalid character. So for example, the string "1-23" will cast to a 1. I need to evaluate the entire string though, so that the string "1-23" would not successfully cast. Is this possible?

Recommended Answers

All 2 Replies

Use is_numeric function.

if(is_numeric($string)) {
    $float = (float) $string;
}

Thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.