|
12.07.2007, 05:56 | #1 |
Участник
|
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 |
Участник
|
Цитата:
Сообщение от 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 X++: int i = any2int(r); |
|
12.07.2007, 18:22 | #3 |
Участник
|
Написано же, any2int значит параметром должен обязательно быть anytype |
|
|
Опции темы | Поиск в этой теме |
Опции просмотра | |
|