Nikon the Third
Nikon the Third

Reputation: 2831

How to put a literal percent sign (%) inside F#'s printf format strings?

I want to print a % sign using F#'s printfn function. After googling the format syntax, this should do the trick: printfn "%%". Apparently not...

F# interactive output:

> printfn "%%";;
%%
val it : unit = ()

Weird...

I'm using F#3.1 and .NET 4.5, the F# interactive session uses .NET 4.0. Same thing.

For reference: printfn "%" doesn't compile (missing format specifier) and printfn "%s" "%" is my current workaround...


Update:

When I change the target F# runtime from 3.1 to 3.0, it works. Is this a bug in the 3.1 runtime?

Upvotes: 11

Views: 2484

Answers (1)

Nikon the Third
Nikon the Third

Reputation: 2831

If printfn "%%" outputs two percent signs (%%) instead of one percent sign (%), then you have to update F# 3.1 to at least version 3.1.1.

If you are using Visual Studio 2013, you can do this via Tools → Extensions and Updates → Updates → Visual Studio Gallery → Visual FSharp Tools.

Upvotes: 9

Related Questions