Fermer2
GoldenCrystalLe 10/05/2013 à 01:43
1666.42859f * 1.4f
2333.0
(int)(1666.42859f * 1.4f)
2332



(decimal)(1666.42859f * 1.4f)
2333
(int)(decimal)(1666.42859f * 1.4f)
2333



(int)(double)((double)1666.42859f * (double)1.4f)
2332
(int)(float)((double)1666.42859f * (double)1.4f)
2333
(int)(float)(double)(1666.42859f * 1.4f)
2333

vtff vtff vtff vtff vtff vtff

Maintenant je cherche une solution élégante pour résoudre ce problème -_-


(Oui, je n'étais encore jamais tombé dans un cas concret où le fonctionnement des float sur x86 me les briserait autant… Il faut une première à tout.)




EDIT:

Premier truc crado qui me vient à l'esprit…private static unsafe int SafeTruncateSingle(float f) { var a = stackalloc float[1]; a[0] = f; return (int)a[0]; }triso
(Ça a l'air de fonctionner, mais en théorie un compilateur pas complètement con devrait savoir optimiser cette méthode… :/)