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

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 12.07.2007, 05:56   #1  
Blog bot is offline
Blog bot
Участник
 
25,559 / 848 (80) +++++++
Регистрация: 28.10.2006
Issues concerning X++: Getting rid of the "Loss of precision" warning message
Источник: http://blogs.msdn.com/x/archive/2007...g-message.aspx
==============

A question came up at today's webinar where a developer had a (presumably legitimate) reason to cast a real value into an integer value. The X++ language does not allow explicit casting (there's no support for it in the language), but the compiler will do its best to satisfy the user and do the conversion on its own. In this case, however, it issues a warning message, lest this is not what the user wanted.
One solution is to use the anytype type to hold the vaue for conversion and then using the any2int function, as shown below:
static void Job47(Args _args)
{ real r = 3.13;
int i = r; // Warning is issued here
anytype a;

a = r; // Assign to an anytype variable...
i = any2int(a); // ... and back into an int

print r;
print i;
pause;

}
This should be packaged into a function, maybe called int RealToInt(real arg).
Another way would be doing the conversion in managed code (through the System.Convert::ToInt32(object) method), but the performance will not be as good because of the marshalling that needs to take place.
I hope this helps.


Источник: http://blogs.msdn.com/x/archive/2007...g-message.aspx
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
Старый 12.07.2007, 18:14   #2  
gl00mie is offline
gl00mie
Участник
MCBMSS
Most Valuable Professional
Лучший по профессии 2017
Лучший по профессии 2015
Лучший по профессии 2014
Лучший по профессии AXAWARD 2013
Лучший по профессии 2011
Лучший по профессии 2009
 
3,684 / 5798 (201) ++++++++++
Регистрация: 28.11.2005
Адрес: Москва
Записей в блоге: 3
Цитата:
Сообщение от Blog bot Посмотреть сообщение
In this case, however, it issues a warning message, lest this is not what the user wanted.
One solution is to use the anytype type to hold the vaue for conversion and then using the any2int function, as shown below:
X++:
real r = 3.13; 
int i = r; // Warning is issued here 
anytype a; 
a = r; // Assign to an anytype variable... 
i = any2int(a); // ... and back into an int
This should be packaged into a function, maybe called int RealToInt(real arg).
О, да, давайте наплодим кучу бесполезных функций... Инетересно, почему нельзя просто написать так?
X++:
int i = any2int(r);
У меня компилятор на это тоже никаких предупреждений не выдает (проверено на AX3.0KR2 и AX4.0SP1) - и не надо плодить лишние функции...
Старый 12.07.2007, 18:22   #3  
kashperuk is offline
kashperuk
Участник
Аватар для kashperuk
MCBMSS
Соотечественники
Сотрудники Microsoft Dynamics
Лучший по профессии 2017
Лучший по профессии 2015
Лучший по профессии 2014
Лучший по профессии 2011
Лучший по профессии 2009
 
4,361 / 2084 (78) +++++++++
Регистрация: 30.05.2004
Адрес: Atlanta, GA, USA

Написано же, any2int
значит параметром должен обязательно быть anytype
 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
Issues concerning X++: Pen based form demo Blog bot DAX Blogs 0 31.10.2007 23:40
Issues concerning X++: Difference between " and ' ? Blog bot DAX Blogs 0 30.10.2007 05:03
axaptafreak: Send message to online user in Dynamics AX 4.0 (quick & dirty) Blog bot DAX Blogs 0 12.04.2007 16:10
поле "Документы к обновлению" в форме "Обработка закупки" sev DAX: Функционал 3 08.12.2005 17:21
"LIKE" и "OR" в "qbds" @x DAX: Программирование 14 20.01.2004 13:20

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

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

Рейтинг@Mail.ru
Часовой пояс GMT +3, время: 02:19.
Powered by vBulletin® v3.8.5. Перевод: zCarot
Контактная информация, Реклама.