Group Abstract Group Abstract

Message Boards Message Boards

0
|
148 Views
|
4 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Rounding a number to a specific significant figure in Wolfram Alpha is not working properly

Posted 4 days ago

Rounding a number to a specific significant figure is not working properly. For example, 1.264911064 to 3 sf results in 1.26491. This problem/bug is recent I guess, because in the past I got correct answers of rounding to sf.

POSTED BY: Tanvir Zawad
4 Replies
Posted 2 days ago

I don't know of a built-in function for this, but here is a user-defined function:

(*sigfiqs required to be integer>0*)
roundTo[num_, sigfigs_] /; IntegerQ[sigfigs] && sigfigs > 0 :=
 Module[{mant, exp, rounded},
  (*mantissa and exponent*)
  {mant, exp} = MantissaExponent[num];
  (*round the mantissa to sigfigs and reconstruct*)
  rounded = Round[mant, 10^-sigfigs] 10^exp;
  (* return integer for integer*)
  If[ IntegerQ[num], rounded, N@rounded]
  ]

roundTo[123456, 3]
(*123000*)

roundTo[12.3456*^-10, 3]
(*1.23`*^-9*)
POSTED BY: David Keith

Have you tried one of these?

x = 1.264911064;
NumberForm[x, 3]
Round[x, 1/100] // N
ResourceFunction["DecimalRound"][x, 3]
POSTED BY: Gianluca Gorni
Posted 1 day ago

And me too! I missed it as well.

POSTED BY: David Keith

Sorry, I had not noticed that you were using Wolfram Alpha. In fact, if I ask WA "round 1.264911064 to three significant digits" the function which gets called is N[1.264911064,3] which gives 1.26491, not what is wanted.

I don't know if this behaviour is recent or not. I get the correct answer asking this:

round 2 Sqrt[2/5] to three significant digits
POSTED BY: Gianluca Gorni
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard