Показать сообщение отдельно
Старый 27.04.2012, 22:11   #1  
Blog bot is offline
Blog bot
Участник
 
25,643 / 848 (80) +++++++
Регистрация: 28.10.2006
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
.

You can use
num2str
to convert your real numbers to a string, or you can use Format.
Example, controlling the number of decimals showed: (decimal point acts as decimal separator)

[COLOR=white !important]?
1
2
3
4
5
6
7
static void FormatExamples(Args _args)
{
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
2
3
4
5
6
7
static void FormatExamples(Args _args)
{
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
hexadecimal
for example.
Example:

[COLOR=white !important]?
1
2
3
4
5
6
7
static void FormatExamples(Args _args)
{
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, напишите личное сообщение администратору.