Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

We know that in Mathematica there is some default precision, which you can also change. This means, that after a certain decimal(fixed by the precision), the computer puts pseudo random numbers. I am looking for a function F that would put everything zero after a certain decimal. Let us say I want this to be the fourth decimal, then


Does such function exist?

Thank you

share|improve this question
Floor[0.12345678, 0.0001] gives 0.1234 and if you want 4 zeros to the right you can use NumberForm[Floor[0.12345678, 0.0001],{4,8}] – tchronis Nov 3 '13 at 11:55
@tchronis thanks great, and can you think of something equivalent for matrices? You can use it for a matrix, but I have realized that after you use it with matrix, Mathematica does not consider it a matrix any more, for example you can do Eigensystem afterwards – Mencia Nov 3 '13 at 12:01
Thanks @Mencia , you can apply Floor to the matrix. I suppose you have rectangular Matrices. Floor[matrix,0.0001] works in my machine. And for nice output you can apply the NumberForm function. – tchronis Nov 3 '13 at 12:05
@tchronis great man, that is exactly what I needed, appreciate!! – Mencia Nov 3 '13 at 12:11
up vote 3 down vote accepted

Here are two approaches (trying to emulate the fomratting it just the truncation):

f[x_, n_] := N[IntegerPart[10^n x]/10^n, StringLength@ToString@x]


g[x_, n_] := N[Floor[10^n x]/10^n, StringLength@ToString@x]






share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.