carx Posted November 7, 2012 Share Posted November 7, 2012 Bonjours je cherche a faire un arrondi a un 0 derrière la virgule, j'ai bien trouver la fonction "around", mais j'ai pas compris comment on l'utiliser . vitesse = location.getSpeed()*3.6;// on dispose la fonction around avant ou après la multiplication ?? private class MyLocationListener implements LocationListener{ public void onLocationchanged(Location location) { vitesse = location.getSpeed()*3.6; ((TextView)findViewById(R.id.Text1)).setText(String.valueOf(vitesse)); } peut-on faire des arrondi avants la virgule aussi ? je vous remercie d'avance pour vos explication ♥♦♣♠ Link to comment Share on other sites More sharing options...
chpil Posted November 8, 2012 Share Posted November 8, 2012 De quelle fonction "around" parles tu ? Pour avoir la partie entière d'un décimal, tu peux utiliser la méthode Math.round: vitesse = Math.round(location.getSpeed()*3.6); Link to comment Share on other sites More sharing options...
carx Posted November 8, 2012 Author Share Posted November 8, 2012 bonjour chpil, je parle bien de la même fonction, vitesse = (Math.round(location.getSpeed()*3.6)); mais il est impossible de sen servir pour faire un autre arrondi autre que décimal ? c'est dommage que cette fonction ne sois pas un peut plus avancer . je te remercie beaucoup Chpil ♥♦♣♠ Link to comment Share on other sites More sharing options...
chpil Posted November 8, 2012 Share Posted November 8, 2012 Quel autre arrondi (que décimal) veux tu faire ?? Link to comment Share on other sites More sharing options...
Lord Yu Posted November 8, 2012 Share Posted November 8, 2012 Pour un chiffre après la virgule : vitesse = (Math.round(location.getSpeed()*3.6*10)/10); Pour 2 ça va être *100)/100, etc. Pas testé mais ça devrait fonctionner. Link to comment Share on other sites More sharing options...
alex971 Posted November 8, 2012 Share Posted November 8, 2012 Bonjour, Sujet transféré :) Link to comment Share on other sites More sharing options...
carx Posted November 8, 2012 Author Share Posted November 8, 2012 Pour un chiffre après la virgule : vitesse = (Math.round(location.getSpeed()*3.6*10)/10); Pour 2 ça va être *100)/100, etc. Pas testé mais ça devrait fonctionner. méthode approuver ^^ :)) juste u a remanier le code un peut public void onLocationchanged(Location location) { vitesse = (Math.round(location.getSpeed()*36)/10); ((TextView)findViewById(R.id.Text1)).setText(String.valueOf(vitesse)); public void onLocationchanged(Location location) { vitesse = (Math.round(location.getSpeed()*36))/10; ((TextView)findViewById(R.id.Text1)).setText(String.valueOf(vitesse)); jusque la arrondi toujours calculer sur décimal une foi l'arrondi calculer avec un zéro de trop "X10" je divise par 10 avants de le renvoyer dans mon "édittext" et la sa marche a merveille !! public void onLocationchanged(Location location) { vitesse = (Math.round(location.getSpeed()*36)); ((TextView)findViewById(R.id.Text1)).setText(String.valueOf(vitesse/10)); je vous remercie tous énormément pour l'aide que vous m'avez apporter . ♥♦♣♠ Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.