Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: how to format decimals?

From: greggirwin::mindspring::com at: 25-Apr-2005 9:46

Hi Janeks, sal> Hi, Rebolers! How to format decimals to show the given number of sal> decimal fraction digits? F.ex.: format 2.3 3 => 2.300 There is nothing like that built in, unfortunately. Eric Long did a formatter, which doesn't seem to be in the library. My old notes say that it didn't work as expected when I tried it--OK for single values, but not for blocks--maybe due to newer REBOL releases doing something different. Eric's design is modeled on sprintf, which isn't really my cup of tea. I have a start on one myself, but it doesn't support custom formats at this time (didn't need them myself when I built it). I can send either, or both, to you if you want. I don't want to post Eric's to REBOL.org if it's broken though. In the meantime, here's a quick hack for your specific need: ; NOT LOCALIZED! pad-decimal: func [value [decimal!] len [integer!] /local s] [ s: form value head insert/dup tail s #"0" len - ((length? s) - index? find s #".") ] -- Gregg