As a follow-up question, why is the following not allowed?

julia> fmt = "%8.1e";

julia> @sprintf(fmt, 3.1415)
ERROR: first or second argument must be a format string

I don't see how it's different from

julia> @sprintf("%8.1e", 3.1415)

What's the appropriate syntax?

Thanks.


On Friday, April 11, 2014 11:24:50 PM UTC-7, Dominique Orban wrote:
>
> Thank you! Such a basic operation could feature a bit more prominently in 
> the documentation.
>
>
> On Friday, April 11, 2014 11:21:28 PM UTC-7, John Myles White wrote:
>>
>> @sprintf
>>
>> On Apr 11, 2014, at 11:18 PM, Dominique Orban <[email protected]> 
>> wrote:
>>
>> Sorry if this is a RTFM, but I can't find the answer in the documentation 
>> or on the web. I may have missed it. I come from Python where I can build 
>> strings with formatted data using a syntax like
>>
>> s = "pi=%7.1e" % acos(-1)
>>
>> How do I accomplish that in Julia? @printf doesn't do the job because it 
>> doesn't return anything:
>>
>> julia> s = @printf("%7.1e", 3.14)
>> 3.1e+00
>> julia> s
>>
>>
>>
>>
>> Thanks.
>>
>>
>>

Reply via email to