Perl program that truncates the amount after the decimal point

Let's create a Perl program that truncates the amount after the decimal point. It can be used for rounding when dividing the amount.

For example, let's assume that the total amount of money borne by the buyer / seller is 9800 yen and the buyer's burden is "33/365". It is not divisible when divided.

In such a case, you can select either round up or round down after the decimal point, but this time, let's consider the case of rounding down.

Truncate the amount after the decimal point

To truncate the amount after the decimal point, use the int function.

use strict;
use warnings;

# Amount (886.027397260274)
my $price = 9800 * (33/365);

# Truncate the amount after the decimal point (886)
my $price_cut = int $price;

# Output result
print "$price_cut\n";

You can copy and paste this program and try it immediately at PerlBanjo.

Associated Information