AXForum  
Вернуться   AXForum > Microsoft Dynamics AX > DAX Blogs
All
Забыли пароль?
Зарегистрироваться Правила Справка Пользователи Сообщения за день Поиск

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 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, напишите личное сообщение администратору.
 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
emeadaxsupport: New Content for Microsoft Dynamics AX 2012 : October 2011 Blog bot DAX Blogs 0 27.10.2011 17:11
axinthefield: How Preallocated Number Sequences are Cached in AX Blog bot DAX Blogs 0 03.05.2011 06:15
axinthefield: Dynamics AX Event IDs Blog bot DAX Blogs 0 01.03.2011 22:11
daxdilip: Whats New in Dynamics AX 2012 (A brief extract from the recently held Tech Conf.) Blog bot DAX Blogs 7 31.01.2011 12:35
axStart: Microsoft Dynamics AX 2009 Hot Topics Web Seminar Series Blog bot DAX Blogs 0 06.08.2008 12:05

Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход

Рейтинг@Mail.ru
Часовой пояс GMT +3, время: 18:05.