in reply to issue with sprintf..

%d means signed integer, you are suffering from an overflow problem.

Since the floating point mantissa is much larger, %f for instance¹ should mitigate the "problem" for some time.

DB<109> $val=12143951645 => "12143951645" DB<110> sprintf("%11.0f", $val); => "12143951645"

Only you can tell us how large your numerical ranges are...

Cheers Rolf

( addicted to the Perl Programming Language)

update

¹) see also this post for discussion of string template %s

Replies are listed 'Best First'.
Re^2: issue with sprintf..
by sathya83aa (Acolyte) on Jan 09, 2014 at 10:35 UTC

    Max length of the variable will be zero. Even the variable is of length 5, I want to prefix '0's to make the length 11. Thats my intention.

      so better use sprintf properly, put a leading 0 in the pattern after %.

      Your s/ /0/ substitution is - politely said - less optimal. ;-)

      DB<117> $val=12143 => 12143 DB<118> sprintf("%011.0f", $val); => "00000012143" DB<119> $val=12143951645 => "12143951645" DB<120> sprintf("%011.0f", $val); => "12143951645"

      please read the documentation for more details. =)

      Cheers Rolf

      ( addicted to the Perl Programming Language)

        You mean to say I can remove that substitution s/ /0/ and simply use "sprintf("%011.0f", $val);" right?

      Or like this:

      $Val2 = '0' x (11-length $Val2) . $Val2 if length $Val2 < 11;

      or this

      $Val2 = substr "00000000000$Val2", -11;