If you begin by writing Raul's idea as an explicit definition, J selects a different choice than his version. However, you can write and explicit definition to produce his verb.
f=: 13 :'":".y' g=: 13 :'":&".y' f [: ": ". g ":&". f 'z' [z=: 5.13e7 51300000 g 'z' [z=: 5.13e7 51300000 Linda -----Original Message----- From: programming-boun...@forums.jsoftware.com [mailto:programming-boun...@forums.jsoftware.com] On Behalf Of Ian Clark Sent: Tuesday, August 25, 2015 11:05 PM To: programm...@jsoftware.com Subject: Re: [Jprogramming] Format a floating number without rounding errors I guess you mean: format=: ":&". So simple. And here was me fooling around with 0j300&": and all sorts. (I had a blind spot from using 5!:5 to handle a much wider range of datatypes.) On Wed, Aug 26, 2015 at 3:55 AM, 'Pascal Jasmin' via Programming <programm...@jsoftware.com> wrote: > ": seems to work with all your examples, and does 6 decimal places automagically. > > > ----- Original Message ----- > From: Ian Clark <earthspo...@gmail.com> > To: programm...@jsoftware.com > Cc: > Sent: Tuesday, August 25, 2015 10:41 PM > Subject: [Jprogramming] Format a floating number without rounding > errors > > Can anyone tell me how to define a verb: format which returns a > numeral string for a noun z of datatype: 'floating' which is formally > identical to the original definition of z, viz > > format 'z' [z=: 5.13 > 5.13 > format 'z' [z=: 5.13e_7 > 5.13e_7 > format 'z' [z=: 5e_7 > 5e_7 > format 'z' [z=: 5e_4 > 0.0005 > > Hitherto I've been using 5!:5 -which gives (or exposes) rounding > errors > > format=: 5!:5&< > format 'z' [z=: 5.13 > 5.12999999999999989 > format 'z' [z=: 5.13e_7 > 5.13000000000000001e_7 > format 'z' [z=: 5e_7 > 4.99999999999999977e_7 > format 'z' [z=: 5e_4 > 0.00050000000000000001 > > I want it to work with the full range of exponents and up to 6 decimal > places (say) of mantissa. > > JVERSION > Engine: j803/2014-10-19-11:11:11 > Library: 8.03.13 > Qt IDE: 1.3.1/5.3.2 > Platform: Darwin 64 > Installer: J803 install > InstallPath: /applications/j64-803 > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm