当前位置: 动力学知识库 > 问答 > 编程问答 >

php - Echoing text between numbers with decimals

问题描述:

I've putted a script together a bit with array's and stuff.

Now in the end, it checks for a score with checkboxes and divides it by ten.

Then with number format i round it off two 2 decimals, it looks like this.

$number = $score / $total;

$number = $number * 10;

$number = number_format(round($number,2),2,',','.');

echo "The number is: $number <br/>";

Then later on, i'm doing this.

if($number < 4 && $number > 0)

echo 'You're number is between zero and 4';

else if($number > 6 && $number < 4)

echo ' You're number is between 4and 6';

else if($number < 8 && $number > 6)

echo' You're number is between 6 and 8';

else if($number < 10 && $number > 8)

You're number is between 8 and 10';

Now, if the number is like, 0.50 or 1.50 or 2 or 5.50 it's shows the text i've provided.

However, if the number is like 4,13 or 7,85 or 9,13 it doesn't.

Searched now quite a while but can't figure it out.

Do you people see a solution?

Hope i was clear enough!

Thanks in advance.

网友答案:

Is this what you're looking for?

<?php
$score = 7; //Example values
$total = 32;

$number = $score / $total;
$number = $number * 10;
$number = round($number,2);
echo 'The number is: ',number_format($number,2,'.',','),' <br/>';

if($number < 4 && $number > 0)
    echo 'Your number is between zero and 4';
else if($number < 6 && $number > 4)
    echo 'Your number is between 4 and 6';
else if($number < 8 && $number > 6)
    echo 'Your number is between 6 and 8';
else if($number < 10 && $number > 8)
    echo 'Your number is between 8 and 10';
?>
网友答案:

The following statement will never validate true:

if($number > 6 && $number < 4) 

Do you know any number that's higher than six and smaller than four?

The code also contains numerous syntax errors, for example:

echo 'You're number is between zero and 4';

The apostrophe needs to be escaped using a backslash:

echo 'You\'re number is between zero and 4';

Or use double quotes for strings containing apostrophes:

echo "You're number is between zero and 4";

Finally, grammar whise, you're should be your :)

分享给朋友:
您可能感兴趣的文章:
随机阅读: