# Tag Info

## New answers tagged number-representation

2

I don't know of a built in method but the method below uses only a few lines of code to achieve this. toPrecision[x_?NumericQ, sigFigs_Integer?Positive] := Module[{y, sign, magnitudeShift}, sign = Sign@x; y = x sign; magnitudeShift = sigFigs - Ceiling@Log10@y; sign Round[y 10^magnitudeShift, 1] 10^-magnitudeShift ] This shifts the number so ...

1

It's unclear what exactly is an input but here's my interpretation: ClearAll[f] f[x_, y_] := 3.23425124 x^2 + 5.8978587 y; f[2, 3] 30.6306 DownValues[f] = DownValues[f] /. n_?NumericQ :> RuleCondition@Round[n, 0.1]; f[2, 3] 30.5

3

3.23425124 x^2 + 5.8978587 y /. Times[a_, b_] :> Times[Round[a, 0.1], b] (*3.2 x^2 + 5.9 y*) coefficient * variable is of Times[coefficient, variable] in full form, therefore you can use this pattern to match and round only the coefficient.

4

n /. Solve[ {n == th*1000 + h*100 + t*10 + u, u > t > h > th, Thread[0 < {th, h, t, u} < 10]} // Flatten, {th, h, t, u, n}, Integers] (* {1234, 1235, 1236, 1237, 1238, 1239, 1245, 1246, 1247, 1248, 1249, \ 1256, 1257, 1258, 1259, 1267, 1268, 1269, 1278, 1279, 1289, 1345, \ 1346, 1347, 1348, 1349, 1356, 1357, 1358, 1359, 1367, 1368, ...

Top 50 recent answers are included