Re: "Sloppy Union"? (Union of a list with *nearly* equ
- To: mathgroup at smc.vnet.net
- Subject: [mg41979] Re: "Sloppy Union"? (Union of a list with *nearly* equ
- From: "Will Self" <wself at msubillings.edu>
- Date: Mon, 16 Jun 2003 03:56:26 -0400 (EDT)
- References: <bc6mt4$2ah$1@smc.vnet.net> <bc7pgs$6f8$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
"AES/newspost" <siegman at stanford.edu> wrote in message news:bc7pgs$6f8$1 at smc.vnet.net... > Is there a built-in Mathematica function to "round" or "chop" the > numerical value of a number (Integer, Real, or Complex) to its first n > significant digits (padding with zeros if needed)? I don't think there is (I'm often wrong about this sort of thing), but this will do it: sigFig[x_, n_] := Module[{m = n - 1 - Floor[Log[10, x]]}, Round[x*10^m]*10.^-m] sigFig[432.1567, 4] sigFig[.04321567, 4] sigFig[234111111, 3] There is something called ScientificForm that displays the result in scientific form with the specified number of significant digits, but this is just a display thing, and does not change the number. But you could use it in combination with sigFig for display purposes: ScientificForm[sigFig[432.1567, 4], 4]