Ticket #4265: OutputFormat.cpp

File OutputFormat.cpp, 764 bytes (added by silamantex, 11 years ago)

updated version 2009.03.05

Line 
1#include "stdafx.h"
2
3#include "OutputFormat.h"
4
5
6// This function adds delimiters by thousands base.
7// Delimiter based on user locale settings.
8CString makeUserFriendlyString(__int64 val)
9{
10 int delimLen = ::GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_STHOUSAND, NULL, 0);
11
12 CString delimStr;
13 delimStr.Preallocate(delimLen);
14
15 ::GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_STHOUSAND, delimStr.GetBuffer(), delimLen);
16
17 CString str;
18 str.Format(_T("%I64d"), val);
19
20 CString result_str;
21 int dec_count = 1;
22 for (int idx = str.GetLength() - 1; idx >=0; idx--)
23 {
24 if (dec_count > 3)
25 {
26 dec_count = 1;
27 result_str += delimStr.GetString();
28 }
29 result_str += str[idx];
30 dec_count++;
31 }
32 return result_str.MakeReverse();
33}
34
35
36