": 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

Reply via email to