The docs for printf are here (the page formatting is currently a little broken):

[link:msdn.microsoft.com]

Does this code help?

1
2
3
4
5
6
7
8
9
10
 

let x = -3.05

let y = 3.14159265358979

printfn "% 7.4f" x

printfn "% 7.4f" y

The " 7.4" says total number width of 7, 4 digits after the decimal, and the space says a leading space for positive numbers (or a '-' for negative numbers).

(But agree with other answer that you might check out .Net String.Format as well.)

By on 1/26/2010 12:59 PM ()

Hello, Brianmcn:
Thank you very much, your code works.
I know most .NET languages can share something in common, but whenever I look at MSDN code samples, for VB/C#, there are always good samples; but for F#, usually no code samples available, some times, it is not easy to figure out how to use the format.
Gary:
I have also figured out how to add element to dictionary, I have to use TryGetValue.
So thank you for your advice.

By on 1/26/2010 1:37 PM ()

If you want to use .NET things in F#, the C# code sample usually are pretty close to what you want.

By on 1/26/2010 2:01 PM ()

.NET has the string.Format function which handles a wide array of formatting option.

And since it is .NET, it has no difference whether it is used in F# or VB so if you were using VB before, you may have used that. Otherwise, just fire up your VB and make use of its intellisense feature to check that function out.

Same goes for the dictionary question. Both are .NET class/function and has nothing to do with F# what so ever. Whatever you know in VB applies equally well in F# for .NET functionalities.

otherwise, search on string.Format on google would help too. Though I find the easiest is still to read the manual and test that out experimentally.

By on 1/26/2010 12:56 PM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper