-2
<?php 
  echo '                                                        <tr>
                                                                <td>John Doe</td>
                                                                <td>34</td>
                                                                <td>44</td>
                                                                <td>' .$ks1. '</td>
                                                                <td>' .$ks1. '</td>
                                                                <td>' . ($ks2 - $ks1) . '</td>
                                                                <td><div class="progress progress-lg">
    <div class="progress-bar" data-progress="' . ($ks1*100 / $ks2) . '"></div>
</div></td>'; ?>

When I run this page, progress bar shows 75.75757575757. I want to get first 4 digit. I try to add substr but it gives error.

<div class="progress-bar" data-progress="'substr(. ($ks2*100 / $ks1) .,1,4);'"></div>
</div></td>'; ?>

How can i fix it? Thanks.

Sedat
  • 3
  • 1

1 Answers1

0

I would use round() in this case:

<?php 
  echo '<tr>
        <td>John Doe</td>
        <td>34</td>
        <td>44</td>
        <td>' .$ks1. '</td>
        <td>' .$ks1. '</td>
        <td>' . ($ks2 - $ks1) . '</td>
        <td><div class="progress progress-lg">
                <div class="progress-bar" data-progress="' . round(($ks1 * 100 / $ks2), 2) . '"></div>
            </div></td>'; 
?>

This will return 75.76 because of the rounding. If you still want 75.75 you can use substr(), but that will only work if the number is between 10 and 99 whereas round() will always return 2 decimals (at most).

KIKO Software
  • 15,283
  • 3
  • 18
  • 33