# 十进制转其他进制

#!/usr/bin/env perl

use strict;
use warnings;
use utf8;
use 5.010;

my $num = 173.7; my$radix = 6;

sub integral
{
my $_integral = int(shift or 0); my$_radix = shift or warn "Please input a radix.n";
my @result = ();
while ($_integral >$_radix) {
push @result, $_integral %$_radix;
$_integral /=$_radix;
}
push@result, int($_integral); my$res = "";
while (scalar @result) {
$res .= pop @result; }$res;
}

sub floating
{
my $_floating = shift or 0; my$_radix = shift or warn "Please input a radix.n";
my $_integral = int($_floating);
$_floating -=$_integral;
my $res = ""; for (my$i = 0; $i < 10;$i++) {
my $tmp = int($_floating * $_radix);$res .= $tmp;$_floating *= $_radix;$_floating -= $tmp; }$res;
}

my ($integral,$floating) = split(/./, $num); say integral($integral,$radix),".",floating "0.".$floating,\$radix;
声明: 本文为0xBBC原创, 转载注明出处喵～

## 2 thoughts on “十进制转其他进制”

1. determ1ne说道：

博主学会用删除线来卖萌了。。

今天要来和博主来个小小的道别。。马上就要中考了所以不能经常来了。。
希望博主能够写出更好的东西来分享给大家！
有空就回来回复的！！

1. 0xBBC说道：

以前是直接用白色字体来卖萌:-p