![]() |
#1 |
Участник
|
ax-erp: How to format your number the CLR style
Источник: http://microsoft-dynamics-ax-erp.blo...clr-style.html
============== Converting (real) numbers to a string representation is a common requirement. There are different roads that lead to Rome, I'll show you some alternatives, which all have one thing in common: They all use Format. num2strYou can use to convert your real numbers to a string, or you can use Format. hexadecimalExample, controlling the number of decimals showed: (decimal point acts as decimal separator) [COLOR=white !important]? 1 static void FormatExamples(Args _args)2 3 4 5 6 7 { real mynumber=123.4; String30 mynumberstr = System.String::Format("{0,0:#.00}", mynumber); ; info(strfmt("Your number is %1", mynumberstr)); } [/COLOR] You can use the Format command to add leading zeros also. Example: [COLOR=white !important]? 1 static void FormatExamples(Args _args)2 3 4 5 6 7 { real mynumber=123; String30 mynumberstr = System.String::Format("{0,0:00000}", mynumber); ; info(strfmt("Your number is %1", mynumberstr)); } [/COLOR] Notice that you can also use rounding like this as well. Besides this basic function, we can actually do some conversions. You can use Format to convert to for example. Example: [COLOR=white !important]? 1 static void FormatExamples(Args _args)2 3 4 5 6 7 { int mynumber=255; String30 mynumberstr = System.String::Format("{0,0:X}", mynumber); ; info(strfmt("Your number in Hex: %1", mynumberstr)); } [/COLOR] Источник: http://microsoft-dynamics-ax-erp.blo...clr-style.html
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору. |
|
|
|