Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 662
Nikon the Third Avatar asked Jun 02 '14 21:06

Nikon the Third


1 Answers

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.

like image 143
Nikon the Third Avatar answered Oct 21 '22 17:10

Nikon the Third