Click here to Skip to main content
11,409,854 members (61,396 online)

C / C++ / MFC

 
AnswerRe: how to registered activex contols PinprofessionalRichard Andrew x6418-Sep-13 11:21 
AnswerRe: how to registered activex contols Pinmember«_Superman_»18-Sep-13 19:35 
QuestionHow to retrive / enumerate CDialog controls PinmemberVaclav_Sal18-Sep-13 4:49 
AnswerRe: How to retrive / enumerate CDialog controls [modified] Pinmemberpasztorpisti18-Sep-13 5:22 
GeneralRe: How to retrive / enumerate CDialog controls PinmemberVaclav_Sal18-Sep-13 8:43 
GeneralRe: How to retrive / enumerate CDialog controls Pinmemberpasztorpisti18-Sep-13 11:58 
GeneralRe: How to retrive / enumerate CDialog controls PinmemberVaclav_Sal18-Sep-13 13:01 
Questionbytes to mb conversion upto two decimal places. [modified] PinmemberLe@rner17-Sep-13 19:55 
hi all,

I have file size in bytes, I am converting it in MB to display,

but or two decimal places its display round off value.

I don't want to round up the value and value should be displayed in two decimal places.

 
QWORD nSize=524285686;
static char szSize[16];
	if (nSize < 1024)
	{		
		sprintf(szSize, "%u Byte", nSize);
	}
	else
	{
		char szScales[] = "KMGTPEZY";
		int nScale = 0;
		for (; nScale < sizeof(szScales); ++nScale)
		{
			if (nSize < 1024 * 1024)
			{
				sprintf(szSize, "%6.2f %cB", nSize / 1024.0f, szScales[nScale]);
				break;
			}
			nSize = (nSize + 512) / 1024;
		}
		if (nScale == sizeof(szScales))
		{
			strcpy(szSize, "Unknown Size");
		}
	}
	return szSize;
 
//its return size=500.00MB
//but in real its = 499.99779319 

thanks in advance.

modified 18-Sep-13 3:18am.

AnswerRe: bytes to mb conversion upto two decimal places. PinmvpRichard MacCutchan17-Sep-13 22:06 
GeneralRe: bytes to mb conversion upto two decimal places. PinmemberLe@rner17-Sep-13 22:27 
GeneralRe: bytes to mb conversion upto two decimal places. PinmvpRichard MacCutchan17-Sep-13 22:35 
GeneralRe: bytes to mb conversion upto two decimal places. PinmemberLe@rner17-Sep-13 22:38 
AnswerRe: bytes to mb conversion upto two decimal places (fixed). [modified] PinmvpCPallini17-Sep-13 22:47 
SuggestionRe: bytes to mb conversion upto two decimal places. Pinmemberpasztorpisti18-Sep-13 0:21 
GeneralRe: bytes to mb conversion upto two decimal places. PinmvpCPallini18-Sep-13 0:32 
AnswerRe: bytes to mb conversion upto two decimal places. PinmemberFlaviu217-Sep-13 23:19 
AnswerRe: bytes to mb conversion upto two decimal places. [modified] Pinmemberpasztorpisti18-Sep-13 0:19 
QuestionCreating a DLL with Web Browser Embedded PinmemberDon Guy17-Sep-13 10:48 
AnswerRe: Creating a DLL with Web Browser Embedded PinprofessionalRichard Andrew x6417-Sep-13 16:34 
AnswerRe: Creating a DLL with Web Browser Embedded PinmvpRichard MacCutchan17-Sep-13 22:04 
GeneralRe: Creating a DLL with Web Browser Embedded PinmemberDon Guy18-Sep-13 5:15 
GeneralRe: Creating a DLL with Web Browser Embedded PinmvpRichard MacCutchan18-Sep-13 5:33 
GeneralRe: Creating a DLL with Web Browser Embedded PinmemberDon Guy18-Sep-13 7:04 
GeneralRe: Creating a DLL with Web Browser Embedded PinmvpRichard MacCutchan18-Sep-13 7:31 
GeneralRe: Creating a DLL with Web Browser Embedded PinmemberDon Guy18-Sep-13 7:52 

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

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


Advertise | Privacy | Mobile
Web01 | 2.8.150414.5 | Last Updated 24 Apr 2015
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid