samedi 26 novembre 2016

Generate a Random Double With Specific 6 Digit decimal

where is the problem of this code? i wanna create a Random Double With Specific 6 decimal Digit and it work fine, but just for 60% :/

double random = Double.parseDouble(String.format("%.6f", new Random().nextDouble())); 
            double SP = 0.0 + (random * (7.0 - 0.0)); 

here is the random noumber that is Generate by this code for 10 times:

  • 6.321637
  • 6.971019999999996
  • 0.763686
  • 0.14724500000000001
  • 0.240456
  • 3.268468
  • 2.112775
  • 2.5137419999999997
  • 4.637668
  • 4.712155

see? there is a bug here :|




Aucun commentaire:

Enregistrer un commentaire