Perl program for rounding down less than 1000 yen
Let's create a Perl program that rounds down less than 1000 yen. This is useful when you want to cut off the standard taxable amount of less than 1000 yen before multiplying by the tax rate.
Suppose the first amount given is "198,223 yen". Let's round down less than 1000 yen to "198,000 yen".
How to truncate less than 1000 yen?
The process of truncating less than 1000 yen is considered as follows.
- Divide by 1000
- Truncate the decimals
- Multiply by 1000
use strict; use warnings; # Amount of money my $price = 198_223; # Divide by 1000 (198.223) my $price_div = $price / 1000; # Extract the integer part (198) my $price_div_cut = int $price_div; Multiply # 1000 (198,000) my $price_cut = $price_div_cut * 1000; # Output result print "$price_cut\n";
Four arithmetic operations and extracting the integer part int function.
You can copy and paste this program and try it immediately at PerlBanjo.