I have an expression with lots of numbers such as
1.000000002, 2.0000000000001, ...
and I would like to automatically set them to
1, 2, ...
how can I do that?
I have an expression with lots of numbers such as
1.000000002, 2.0000000000001, ...
and I would like to automatically set them to
1, 2, ...
how can I do that?
A friend of mine gave me a nice answer and I will post it here for completeness.
Use "Rationalize".
Rationalize /@ {1.000000002, 2.0000000000001} doesn't work, you'll have to specify a "catching range": something like Rationalize[#, 10^-8] & /@ {1.000000002, 2.0000000000001}.
– Roman
Feb 28 '19 at 16:04
Rationalize[] solves your problem.
– J. M.'s missing motivation
Mar 01 '19 at 09:18
Roundthem to the nearest integer – Roman Feb 28 '19 at 10:19Chop[1.000000002, 10^(-5)]– Feb 28 '19 at 10:55Floor[]? – OkkesDulgerci Feb 28 '19 at 13:32Round,Floor, etc. have an optional argument that lets you specify their "granularity". For example,Round[x, 1/1000]rounds to the nearest thousandth. Your own solution usingRationalizehas this parameter too and is even more flexible. – Roman Feb 28 '19 at 16:061.000000002(if you look at theFullForm). – Michael E2 Mar 01 '19 at 00:50