[Haskell-cafe] Best way to format a number
Don Stewart
dons at galois.com
Tue Nov 20 22:07:28 EST 2007
briqueabraque:
> Hi,
>
> I would like to get a string for a number
> using always 2 digits (i.e., 75 would be
> "75", 3 would became "03"). What is the
> best way to do that? I tried
>
> printf "%02d\n" 3
>
> which gives me the correct string, but
> ghci always ends that call with a
>
> *** Exception: Prelude.undefined
>
> message. What else should I try? Can
> Text.PrettyPrint do that?
>
It's to do with ghci's defaulting. This is fixed in ghc 6.8:
Prelude Text.Printf> printf "%02d\n" 3
03
You can work around it for now with:
Prelude Text.Printf> printf "%02d\n" 3 >> return ()
03
-- Don
More information about the Haskell-Cafe
mailing list