0

My script is:

#!/bin/bash
num1=32.55
num2=145.958
printf "%5.2f\n" $num1
printf "%5.2f\n" $num2

The output is:

32.55
145.96

Instead of:

   32.55
  145.96

What's going on? If it's any help, I'm using Fedora 27 Beta with Linux Kernel 4.13.8-300.fc27.x86_64

6

The width specifier is for all characters including the decimal point and fraction. Your numbers already have at least 5 characters, so...

$ printf "%8.2f\n" 32.55
   32.55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.