Click here to Skip to main content
16,009,185 members
Home / Discussions / Managed C++/CLI
   

Managed C++/CLI

 
GeneralRe: Forms.. Pin
Luc Pattyn28-Oct-07 17:42
sitebuilderLuc Pattyn28-Oct-07 17:42 
QuestionMessage Removed Pin
26-Oct-07 15:39
Armond Sarkisian26-Oct-07 15:39 
AnswerRe: Logging Into A Windows Shared Folder Pin
TJoe29-Oct-07 6:28
TJoe29-Oct-07 6:28 
QuestionSystem::Math::Round(double, 2) not behaving correctly Pin
BuckBrown26-Oct-07 11:37
BuckBrown26-Oct-07 11:37 
AnswerRe: System::Math::Round(double, 2) not behaving correctly Pin
George L. Jackson26-Oct-07 16:18
George L. Jackson26-Oct-07 16:18 
GeneralRe: System::Math::Round(double, 2) not behaving correctly Pin
BuckBrown29-Oct-07 8:36
BuckBrown29-Oct-07 8:36 
GeneralRe: System::Math::Round(double, 2) not behaving correctly Pin
Mark Salsbery29-Oct-07 9:14
Mark Salsbery29-Oct-07 9:14 
AnswerRe: System::Math::Round(double, 2) not behaving correctly Pin
Luc Pattyn26-Oct-07 16:35
sitebuilderLuc Pattyn26-Oct-07 16:35 
Hi Buck,

the way floats/doubles are stored in binary makes it impossible to exactly represent most
values, especially the ones that seem like round numbers to humans thinking using base ten.

So 4, 2, 1, 0.5, 3.5, 3.75 and many others are representable exactly (basically since
they all equal an integer divided by some power of 2); but 0.2, 3.6 and 3.8 and an infinite
number of other values are not.

Now whatever float/double function you call, if it returns a float/double will suffer
from the same phenomenon. So the only way to really get "3.6" or "3.8" is by using a
function that not only rounds but returns a string. I trust there are some formatting
methods that do just that in C++; ToString() should be one of them, given an appropriate
format specifier.

BTW: to circumvent this problem, especially for monetary numbers, they introduced
the "decimal" data type (which basically stores decimal digits). Maybe that's what you
need in your app.

Smile | :)






Luc Pattyn [Forum Guidelines] [My Articles]


this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google


GeneralRe: System::Math::Round(double, 2) not behaving correctly Pin
Mark Salsbery27-Oct-07 7:18
Mark Salsbery27-Oct-07 7:18 
QuestionCan SaveFileDialog be forced to top? Pin
BuckBrown26-Oct-07 10:54
BuckBrown26-Oct-07 10:54 
AnswerRe: Can SaveFileDialog be forced to top? Pin
Luc Pattyn26-Oct-07 11:18
sitebuilderLuc Pattyn26-Oct-07 11:18 
GeneralRe: Can SaveFileDialog be forced to top? Pin
BuckBrown26-Oct-07 11:41
BuckBrown26-Oct-07 11:41 
QuestionHow to make a listener on a folder, for client-server data synchronization? Pin
Caetano.n.a26-Oct-07 1:52
Caetano.n.a26-Oct-07 1:52 
AnswerRe: How to make a listener on a folder, for client-server data synchronization? Pin
Giorgi Dalakishvili26-Oct-07 6:26
mentorGiorgi Dalakishvili26-Oct-07 6:26 
GeneralRe: How to make a listener on a folder, for client-server data synchronization? Pin
George L. Jackson26-Oct-07 9:34
George L. Jackson26-Oct-07 9:34 
AnswerRe: How to make a listener on a folder, for client-server data synchronization? Pin
George L. Jackson26-Oct-07 9:34
George L. Jackson26-Oct-07 9:34 
Questionhow to import dll in c++ ? Pin
cmpeng3426-Oct-07 0:37
cmpeng3426-Oct-07 0:37 
AnswerRe: how to import dll in c++ ? Pin
Jonathan [Darka]26-Oct-07 1:00
professionalJonathan [Darka]26-Oct-07 1:00 
Questionchar * to String^ Pin
KienNT7825-Oct-07 21:28
KienNT7825-Oct-07 21:28 
AnswerRe: char * to String^ [modified] Pin
Mark Salsbery26-Oct-07 6:28
Mark Salsbery26-Oct-07 6:28 
AnswerRe: char * to String^ Pin
Newbie0026-Oct-07 7:10
Newbie0026-Oct-07 7:10 
GeneralRe: char * to String^ Pin
KienNT7826-Oct-07 7:40
KienNT7826-Oct-07 7:40 
GeneralRe: char * to String^ Pin
Newbie0026-Oct-07 9:01
Newbie0026-Oct-07 9:01 
QuestionLIBC.LIB Not found Pin
Sumanta Rout25-Oct-07 19:24
Sumanta Rout25-Oct-07 19:24 
QuestionGet Computer name Pin
staticplus25-Oct-07 3:13
staticplus25-Oct-07 3:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.