Both the advice from SankoR and, even more so, the observation by FunkyMonk are clearly on target. In the hope of offering some additional clarity:
printf produces output; sprintf merely formats
However, I'm perplexed by your use of "string" in the phrase "save it as a string" as well as by some other aspects of the question. For example, do you mean that $n and $u are floating point numbers (assumed below) or can they be ints; a mixture; or something else??
All the above leads me to send a question back: Does this come somewhere close to your intent?
#!/usr/bin/perl use strict; use warnings; # 816487 my $n = 3.123; my $u = 3.678; my $i= 0; my (@array, $array); for (1..10) { $n -= ($n * $u) * $u; $array[$i] = int(abs($n)); $i++ } for (@array) { print "$_ \n"; }
Output, for $n=3.123, $u=3.678
39 490 6140 76922 963664 12072486 151240294 1894690621 23736085384 297358177092
and for $n=3.123, $u=4.0
46 702 10540 158101 2371528 35572921 533593828 8003907421 120058611328 1800879169921
And another question: "Waaaay off? Helpful?" (I hope the latter.)
In reply to Re: printf function alternative? formatting without printing
by ww
in thread printf function alternative? formatting without printing
by fraizerangus
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |