Jump to content

[SOLVED] if Decimal starts with, return XXXXX


Recommended Posts

Hi,

 

I'm having a problem trying to figure out how I would make my script return the type of the decimal it is, which would be: Reset Mode, Recommended, Hot!, and Dangerous!

 

To achieve this; the decimal's first number, beside zero, would determine the its statues. If the decimal starts with 1 it outputs Reset Mode, if 2 it outputs Recommended, if 3 it outputs Hot! and if 4 and/or above it outputs Dangerous!. How do I go on about this?

Example:

0.00000435345323

 

Output:

This decimal is in Dangerous mode!

<?php
function wx($var) {
$values = array('1'=>'Reset Mode','2'=>'Recommended','3'=>'HOT!','4'=>'Dangerous!');

$length = strlen($var);

for($i=0;$i<=$length;$i++) {

	$temp = substr($var,$i,1);
	if($temp != '0' && $temp != '.'){

		$i = $length + 10;
		if($temp>=4){
			return $values[4];
		}else{
			return $values[$temp];
		}
	}
}
}

echo wx('0.0000234');
?>

 

Test this and it works. This outputs "Recommended"

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.