La matematica è un'opinione per Visual Basic? oppure ho sbagliato qualcosa?
guardate qui e provate voi stessi.
Public Function De(number) As Single
De = Val(Replace(Str(number), ",", "."))
End Function
Public Function RoundEc(number) As Single
number = number * 100
decim = number - Fix(number) 'l'errore è qui.
'[...]
End Function
public sub command1_click()
ore = Split(Text3.Text, ".")
ore_h = Int(Val(ore(0)))
ore_m = Int(Val(ore(1)))
ore_m_d = ore_m * 100 / 60
ore_d = ore_h & "." & ore_m_d 'trasforma in decimale una text "hh.mm", quindi 12.30 = 12,5
ore_d = Val(ore_d)
ore_dec = RoundEc(CSng(De(Text4.Text) * ore_d))
end sub
Allora, se io metto nella text delle ore (hh.mm) 25.30 e nella text4 12,15, la variabile decim diventa 0,4980... mentre dovrebbe semplicemente essere 0,5. BOH!!!
(25.5 * 12.15 = 309.825 ---> 309.825 *100 = 30982.5 ---> 30982.5-30982(.00) = 0.5 e non 0.4980...
Cosa c'è di sbagliato?