Formatted numeric output: Difference between revisions
Content added Content deleted
(Added Fōrmulæ) |
|||
Line 1,099: | Line 1,099: | ||
=={{header|Julia}}== |
=={{header|Julia}}== |
||
Julia's <tt>@sprintf</tt> macro provides string formatting that is similar to that of the c function of the same name. Though easy to use and efficient, <tt>@sprintf</tt> has limited flexibility, as its format specification must be a string literal, precluding its use in dynamic formatting. Greater flexibility is available via the <tt>Formatting</tt> package, which provides an implementation of Python's format specification mini-language. This solution demonstrates both of these techniques to provide the leading zero padded floating point format suggested in the task description ("%09.3f"). |
Julia's <tt>@sprintf</tt> macro provides string formatting that is similar to that of the c function of the same name. Though easy to use and efficient, <tt>@sprintf</tt> has limited flexibility, as its format specification must be a string literal, precluding its use in dynamic formatting. Greater flexibility is available via the <tt>Formatting</tt> package, which provides an implementation of Python's format specification mini-language. This solution demonstrates both of these techniques to provide the leading zero padded floating point format suggested in the task description ("%09.3f"). |
||
<lang Julia> |
<lang Julia>using Printf |
||
test = [7.125, [rand()*10^rand(0:4) for i in 1:9]] |
test = [7.125, [rand()*10^rand(0:4) for i in 1:9]] |
||