Wednesday, August 10, 2022

[FIXED] How to truncate a number

Issue

I should display numbers to a table. But I need The number has only two characters after a comma. How to do it correctly.

            $score =  $schet;
%>
            <tr class="ten" >
                <td class="six" > <%= $schet %></td>
                <td> <%= $d->start %></td>
                <td> <%= $d->end   %></td>
            </tr>
<%
        }

Solution

Use sprintf:

my $number_with_two_decimal_places = sprintf '%.2f', $float;


Answered By - choroba
Answer Checked By - Candace Johnson (PHPFixing Volunteer)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.