Ah, your version is way better!Love the groupBy function. 😄 Cheers! Dustin
Sent from my iPhone > On Apr 30, 2017, at 8:10 PM, Dwayne Crooks <[email protected]> wrote: > > I posted here as the other thread seems to be closed off from replies. > > For this particular app I'm writing/porting the SPA from scratch to Elm and > the formatting issue was the first small hiccup I ran into. As suggested in > the other thread I went ahead and wrote the code I needed in Elm. > > Here it is in case anyone else is interested: > >> module Format exposing (asMoney) >> >> asMoney : Float -> String >> asMoney value = >> let >> totalCents = round (value * 100) >> dollars = totalCents // 100 >> cents = totalCents % 100 >> in >> "$" ++ (groupBy 3 ',' dollars) ++ "." ++ (zeroPad 2 cents) >> >> groupBy : Int -> Char -> Int -> String >> groupBy per sep n = >> let >> pow10 = 10 ^ per >> in >> if n < pow10 then >> toString n >> else >> zeroPad 3 (n % pow10) >> |> String.cons sep >> |> String.append (groupBy per sep <| n // pow10) >> >> zeroPad : Int -> Int -> String >> zeroPad k n = String.padLeft k '0' (toString n) > > P.S. Dustin, I decided to write one for myself. But thanks. > > My next task is to draw some charts using Highcharts. I expect ports would be > the approach here so I'm crossing my fingers and hoping it all works out. I > certainly won't want to be re-writing parts of Highcharts at this point. > -- > You received this message because you are subscribed to the Google Groups > "Elm Discuss" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "Elm Discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
