Extract N number of digits after the dot

2 vues (au cours des 30 derniers jours)
neamah al-naffakh
neamah al-naffakh le 9 Oct 2017
Commenté : Star Strider le 9 Oct 2017
Hi guys,
suppose N=1234.4345
I would like to store in this variable the decimal number and the first two digits only after the dot.
(e.g. N=1234.43 )
Kind Regards.

Réponse acceptée

Star Strider
Star Strider le 9 Oct 2017
You can use the most recent version of the round function, or use this emulation of it:
roundn = @(x,n) round(x .* 10.^n)./10.^n; % Round ‘x’ To ‘n’ Digits, Emulates Latest ‘round’ Function
N = 1234.4345
N = roundn(N,2)
N =
1234.4345
N =
1234.43
  2 commentaires
neamah al-naffakh
neamah al-naffakh le 9 Oct 2017
thank you so much
Star Strider
Star Strider le 9 Oct 2017
As always, my pleasure.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by