[XPAND] Convert real to integer [message #836192] |
Wed, 04 April 2012 07:27 |
Ricardo Ben Amor Messages: 51 Registered: March 2012 |
Member |
|
|
Hi,
I do some researsch in the forum but i don't find an answer to my problem. I'm sure my problem can be solve quickly...
I'm working in a xpand model. I make a calculation with some arguments, and in last i found a REAL number (ex : 79,99456). I would like to convert this real number in an integer, to obtain for example the number 79.
I try to convert my real to string, and convert it in integer but it still dont work.
Example of my program :
«(EcuConfiguration.microPerCycle.first()/2778.0)»,
Result :
71.99424046076314,
Thank you in advance,
Best regards,
|
|
|
|
|
|
|
|
|
|
|
|
Re: [XPAND] Convert real to integer [message #836333 is a reply to message #836323] |
Wed, 04 April 2012 11:04 |
|
of course you could use the things xpand/xtend offer an create an .ext file with an (java) extension that calls some java code
that does the conversion
e.g.
MyExtensions.ext
Integer toIntegerForGuysWhoUse5YearOldoAW(Real r) :
JAVA metamodel.MyExtensions.toIntegerForGuysWhoUse5YearOldoAW(java.lang.Double);
public class MyExtensions {
public static Integer toIntegerForGuysWhoUse5YearOldoAW(Double d) {
if (d == null) return null;
return (int)d.doubleValue();
}
}
«EXTENSION metamodel::MyExtensions»
...
«(1.0/2.0).toIntegerForGuysWhoUse5YearOldoAW()»
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03938 seconds