ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   NumberFormatInfo and Custom Numeric Format Strings (https://www.excelbanter.com/excel-programming/408487-numberformatinfo-custom-numeric-format-strings.html)

Ralf Steinstraesser

NumberFormatInfo and Custom Numeric Format Strings
 
Does anyone know how to initialize a NumberFormatInfo instance with a custom
numeric format string?

So instead of directly using the custom numeric format string

double dVal = 19.95;
string strVal = dVal .ToString("$#,##0.00");
// - strVal is $19.95

I would like to first initialize the NumberFormatInfo instance:

NumberFormatInfo mobjNumFormat = NumberFormatInfo.CurrentInfo.Clone();
mobjNumFormat.InitWithCustomFormat("$#,##0.00");
string strVal = dVal.ToString("C",mobjNumFormat))

Cheers, Ralf

--
Dipl.-Ing. Ralf Steinstraesser
Software Architekt
Bissantz & Company GmbH



All times are GMT +1. The time now is 01:41 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com