This is covered well in the documentation on sprintf (ri sprintf or man 2
printf).

>> "%.2f" % 13.5
=> "13.50"
>> "%d.%02d" % (13.5 * 100).divmod(100)
=> "13.50"

With your example, it should be:
>> "%d.%02d" % [12344444444444, 10]

-a

On Wed, Mar 11, 2015 at 5:23 PM, Raj Sahae <rajsahae / gmail.com> wrote:

> I'm not sure if it's the best way, but you could left justify the last
> digit and then do a gsub on spaces to put the 0's in?
>
>  2.1.3 :011 > ("$%d.%-05d" % [12344444444444, 1]).gsub(/\s/, '0')
>  => "$12344444444444.10000"
>  2.1.3 :012 > sprintf("$%d.%-05d", 12344444444444, 1).gsub(/\s/, '0')
>  => "$12344444444444.10000"
>
>
> --
> Sent from Mailbox <https://www.dropbox.com/mailbox>
>
>
> On Wed, Mar 11, 2015 at 2:07 PM, Arup Rakshit <aruprakshit / rocketmail.com>
> wrote:
>
>> Hi,
>>
>> If I want to pad with `0`, then the below is fine :
>>
>> "$%d.%02d" % [12344444444444, 1] # => "$12344444444444.01"
>>
>> If, I want to remove trailing `0`, then simply :
>>
>> "%g" % 1.0 # 1
>>
>> But, I am looking for how can I add trailing `0`s . I want
>> "$12344444444444.10" instead of `"$12344444444444.01"`.
>>
>> --
>> ================
>> Regards,
>> Arup Rakshit
>> ================
>> Debugging is twice as hard as writing the code in the first place.
>> Therefore, if you write the code as cleverly as possible, you are, by
>> definition, not smart enough to debug it.
>>
>> --Brian Kernighan
>>
>
>


-- 
Austin Ziegler * halostatue / gmail.com * austin / halostatue.ca
http://www.halostatue.ca/ * http://twitter.com/halostatue