Click here to Skip to main content
15,919,613 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: VS 7.1 On Windows XP Pin
Jim Crafton27-Jan-05 17:10
Jim Crafton27-Jan-05 17:10 
GeneralRe: VS 7.1 On Windows XP Pin
rbid27-Jan-05 23:57
rbid27-Jan-05 23:57 
GeneralRe: VS 7.1 On Windows XP Pin
Grahamfff28-Jan-05 9:50
Grahamfff28-Jan-05 9:50 
Generalconvert double to char Pin
Sam197927-Jan-05 10:42
Sam197927-Jan-05 10:42 
GeneralRe: convert double to char Pin
Chris Losinger27-Jan-05 11:03
professionalChris Losinger27-Jan-05 11:03 
GeneralRe: convert double to char Pin
Jim Crafton27-Jan-05 17:07
Jim Crafton27-Jan-05 17:07 
GeneralRe: convert double to char Pin
trelliot27-Jan-05 13:16
trelliot27-Jan-05 13:16 
GeneralRe: convert double to char Pin
trelliot27-Jan-05 17:20
trelliot27-Jan-05 17:20 
Sorry, I misinterpreted your question in my previous reply.
The short answer is that you have exceeded the floating point (or is it printf?) library precision by using 11 + 5 digits (excluding the decimal point).

This example may help you understand what is going on:

// test.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <conio.h> // for getch()

int _tmain(int argc, _TCHAR* argv[])
{
char buffer[64];
double dNum;
int MaxPrecision = 8;
int Precision;
double Divisor;
long MaxDecimal;

for(double dblNum = 8888; dblNum <= 88888888888; dblNum = dblNum * 10 + 8)
{
for(int CurPrecision = 1; CurPrecision <= MaxPrecision; CurPrecision++)
{
dNum = dblNum;
Divisor = 10.0;
fprintf(stdout, "\nCurrent Precision: %u\n\n", CurPrecision);

for(Precision = 0, MaxDecimal = 0; Precision < CurPrecision; Precision++)
MaxDecimal = MaxDecimal * 10 + 9;

for(Precision = 0; Precision <= CurPrecision; Precision++)
{
int CharCount;

CharCount = sprintf(buffer, "%.*f", CurPrecision, dNum);
fprintf(stdout, "%s\t", buffer);

CharCount = sprintf(buffer, "%.*f", Precision, dNum);
if(CharCount >= 0)
{
int i;
if(!strchr(buffer, '.'))
{
buffer[CharCount] = '.';
CharCount++;
}
for(i = 0; i < CurPrecision - Precision; i++)
buffer[CharCount + i] = '0';

buffer[CharCount + i] = 0;
}

fprintf(stdout, "%s\n", buffer);

dNum = dNum + (9 / Divisor);
Divisor *= 10;
}
}
}
getch();
return 0;
}

If you run the example, you will notice that things become decidedly 'iffy' when you reach the 16 char output limit. The reason the second sprintf statement works better is that it is forcing rounding of the decimal part (so it must be printf that is the culprit), but since your problem states that the maximum number of digits is 15, you should have no problem with these limits.
GeneralRe: convert double to char Pin
JKallen27-Jan-05 17:32
JKallen27-Jan-05 17:32 
GeneralRe: convert double to char Pin
Mircea Puiu29-Jan-05 5:16
Mircea Puiu29-Jan-05 5:16 
QuestionIs a directory on local PC? Pin
Neville Franks27-Jan-05 10:34
Neville Franks27-Jan-05 10:34 
AnswerRe: Is a directory on local PC? Pin
David Crow27-Jan-05 10:45
David Crow27-Jan-05 10:45 
GeneralRe: Is a directory on local PC? Pin
Neville Franks27-Jan-05 10:53
Neville Franks27-Jan-05 10:53 
Generalindex of min_element Pin
ns27-Jan-05 10:30
ns27-Jan-05 10:30 
Generalload jpeg into memory as bitmap Pin
Pia G27-Jan-05 9:11
Pia G27-Jan-05 9:11 
GeneralRe: load jpeg into memory as bitmap Pin
Neville Franks27-Jan-05 9:30
Neville Franks27-Jan-05 9:30 
GeneralRe: load jpeg into memory as bitmap Pin
PJ Arends27-Jan-05 9:49
professionalPJ Arends27-Jan-05 9:49 
QuestionHow to find Child window? Pin
Dody_DK27-Jan-05 8:34
Dody_DK27-Jan-05 8:34 
AnswerRe: How to find Child window? Pin
Wes Aday27-Jan-05 9:17
professionalWes Aday27-Jan-05 9:17 
GeneralRe: How to find Child window? Pin
Neville Franks27-Jan-05 9:33
Neville Franks27-Jan-05 9:33 
AnswerRe: How to find Child window? Pin
ThatsAlok27-Jan-05 18:56
ThatsAlok27-Jan-05 18:56 
AnswerRe: How to find Child window? Pin
rwestgraham29-Jan-05 23:01
rwestgraham29-Jan-05 23:01 
GeneralRe: How to find Child window? Pin
Dody_DK30-Jan-05 0:39
Dody_DK30-Jan-05 0:39 
GeneralRe: How to find Child window? Pin
rwestgraham30-Jan-05 14:19
rwestgraham30-Jan-05 14:19 
GeneralRe: How to find Child window? Pin
Dody_DK31-Jan-05 9:59
Dody_DK31-Jan-05 9:59 

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.