efim
asked on
Printing the numbers in the specified format
I need to display the numbers with the dots dividing the millions, thousands and so on.( e.g. number 123456789 has to print like 123.456.789).
Is there a simple and elegant solution for doing this (I can do it by converting into a string and doing some manipulations with it).?
Is there a simple and elegant solution for doing this (I can do it by converting into a string and doing some manipulations with it).?
One way to do this is to convert the number to a string. Find the length of the string (in your case 9). Find the remainder of length divided by 3, or length modulo 3 (in your case 0). This tells you how many numbers to skip from the beginning of the string before printing the separator (in your case, 0 is a special case and you should change it to 3). After displaying the first separator, print 3 digits and if there are any digits left, print a separator. Continue until the end of the original string.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If you're using VC++ you could use
COleCurrency::Format
CString Format( DWORD dwFlags = 0, LCID lcid = LANG_USER_DEFAULT );
Return Value
A CString that contains the formatted currency value.
Parameters
dwFlags
Indicates flags for locale settings, possibly the following flag:
LOCALE_NOUSEROVERRIDE Use the system default locale settings, rather than custom user settings.
lcid
Indicates locale ID to use for the conversion.
Remarks
Call this member function to create a formatted representation of the currency value. It formats the value using the national language specifications (locale IDs). A currency symbol is not included in the value returned. If the status of this COleCurrency object is null, the return value is an empty string. If the status is invalid, the return string is specified by the string resource IDS_INVALID_CURRENCY.
COleCurrency::Format
CString Format( DWORD dwFlags = 0, LCID lcid = LANG_USER_DEFAULT );
Return Value
A CString that contains the formatted currency value.
Parameters
dwFlags
Indicates flags for locale settings, possibly the following flag:
LOCALE_NOUSEROVERRIDE Use the system default locale settings, rather than custom user settings.
lcid
Indicates locale ID to use for the conversion.
Remarks
Call this member function to create a formatted representation of the currency value. It formats the value using the national language specifications (locale IDs). A currency symbol is not included in the value returned. If the status of this COleCurrency object is null, the return value is an empty string. If the status is invalid, the return string is specified by the string resource IDS_INVALID_CURRENCY.