- fix to strip all the decimals
- round can change the integer part
how can I convert a decimal to an integer?
    383 vues (au cours des 30 derniers jours)
  
       Afficher commentaires plus anciens
    
    sadel
      
 le 26 Juin 2011
  
    
    
    
    
    Modifié(e) : Szymon Buchaniec
      
 le 14 Mai 2020
            how can I convert a decimal to an integer?
example
1.232422->1
2123.43242322->2123
0 commentaires
Réponse acceptée
  Oleg Komarov
      
      
 le 26 Juin 2011
        fix  (1.9) % 1
round(1.9) % 2
0 commentaires
Plus de réponses (3)
  Szymon Buchaniec
      
 le 14 Mai 2020
        
      Modifié(e) : Szymon Buchaniec
      
 le 14 Mai 2020
  
      All the proposed answers:
- round(x) - round to the closest integer to x
- floor(x) - round to the nearest integer less or equal to x
- ceil(x) - round to the nearest integer greater than or equal to x
- fix(x) - round to the nearest integer towards 0 (floor(x) for x >=0 and ceil(x) for x<=0)
does not convert the number, but only rounds it. Type of the number is still the same. To convert a decimal (double) number to an integer, one needs to use Conversion Functions. Rounding is automatic, but can be chosen explicitly. Examples:
- uint16(1.8) -> 2
- int32(floor(1.8)) -> 1
0 commentaires
  Willem Dorff
 le 19 Fév 2020
        floor() to round down to nearest integer
ceil() to round up to nearest integer
0 commentaires
Voir également
Catégories
				En savoir plus sur Elementary Math 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!




