Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Truncate decimal numbers in Wolfram Mathematica?

Is there a quick and easy way to truncate a decimal number, say beyond 4 digits, in MATHEMATICA?

With N[1/6, 4] it rounds to =1.6667.

I want you to cut to 1.6666.

Thanks!

like image 572
jose Avatar asked Jan 29 '26 09:01

jose


1 Answers

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

f[1/6, 4]

1.6666

However, note

f[N[531/25], 4]

21.2399

so really some further refinement is required.

like image 109
Chris Degnen Avatar answered Jan 31 '26 06:01

Chris Degnen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!