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

  • 2
    $\begingroup$ 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}] $\endgroup$ – tchronis Nov 3 '13 at 11:55
  • $\begingroup$ @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 $\endgroup$ – Mencia Nov 3 '13 at 12:01
  • 1
    $\begingroup$ 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. $\endgroup$ – tchronis Nov 3 '13 at 12:05
  • $\begingroup$ @tchronis great man, that is exactly what I needed, appreciate!! $\endgroup$ – Mencia Nov 3 '13 at 12:11

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]







Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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