NetXMS Support Forum

English Support => General Support => Topic started by: Millenium7 on October 03, 2024, 05:39:21 AM

Title: No way to convert float to integer??
Post by: Millenium7 on October 03, 2024, 05:39:21 AM
I can't figure this out, there seems to be no way to convert a float to an integer
Documentation says that Math::Floor as well as Math::Round should return an integer, but they do not

Test code that shows all 3 values are returned as type 'real'. So how do I convert a to an integer to be able to use certain math operations correctly (i.e. modulus operator)

a = 12.34;
b = Math::Floor(a);
c = Math::Round(a,0);

println(a);
println(b);
println(c);

println(typeof(a));
println(typeof(b));
println(typeof(c));
Title: Re: No way to convert float to integer??
Post by: Filipp Sudanov on October 03, 2024, 02:25:53 PM
You can do type conversion this way:

b = Math::Floor(12.34);
b = int32(a); println(typeof(b), b);
b = int64(a); println(typeof(b), b);
b = uint32(a); println(typeof(b), b);
b = uint64(a); println(typeof(b), b);
b = real(a); println(typeof(b), b);
b = boolean(a); println(typeof(b), b);