Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Modular syntax
Message
De
22/06/2010 11:54:32
 
 
À
22/06/2010 11:28:57
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Titre:
Versions des environnements
Environment:
VB 9.0
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01470166
Message ID:
01470172
Vues:
47
>If I do this in Visual FoxPro:
>
>
>? MOD(46.90,0.05)
>
>
>I obtain 0.
>
>If I do this in .NET:
>
>
>MessageBox.Show((46.9 Mod 0.05).ToString)
>
>
>I obtain 0.049999999999996.
>
>Can someone explain me why I cannot get the same?


That must be due to the fact that the fractional part of one or both numbers cannot be exactly represented

Workarounds

(1) multiply both by 100, divide the result by 100
Console.WriteLine("{0}", ((46.9 * 100.0) % (.05 * 100.0))/100.0);
(2) do the operation in decimal type
Console.WriteLine("{0}", 46.9m % .05m);

or

Console.WriteLine("{0}", (double)((decimal)46.9 % (decimal).05));
Gregory
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform