printf格式化输出

[root@mysql1 perl]# cat test1.pl   
#!/usr/bin/env perl


use strict;
use warnings;


my $user='gw';
my $days_to_die=36500;
printf "hello, %s; your password expires in %d days!\n", $user,$days_to_die;


# %g浮点数
printf "%g %g %g\n",5/2,51/17,51 ** 17;


# %d整数
printf "in %d days!\n",17.85;


# 指定宽度,如果数据太长,可以自动扩展
printf "%6d\n",42;
printf "%2d\n",2e3+1.95;


# %s字符串 
printf "%10s\n","wilma";


# 宽度为负数,向左对齐,适用上面的各种转换
printf "%-15s\n","flintsone";


# %f浮点数四舍五入
printf "%12f\n",6*7+2/3;
printf "%12.3f\n",6*7+2/3;
printf "%12.0f\n",6*7+2/3;


# 输出百分号,用%%
printf "monthly interest rate: %.2f%%\n",5.25/12;
[root@mysql1 perl]# ./test1.pl   
hello, gw; your password expires in 36500 days!
2.5 3 1.0683e+29
in 17 days!
    42
2001
     wilma
flintsone      
   42.666667
      42.667
          43
monthly interest rate: 0.44%
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值