mBlock is not transfering floating point (.0) to code


#1

Dear friends,

I love mblock, using V5.4.3, but there’s something i can’t wrap my head around, and it’s this:

On https://www.arduino.cc/reference/en/language/variables/data-types/float/ it is stated that:

x = 1;
y = x / 2; // y now contains 0, ints can’t hold fractions
z = (float)x / 2.0; // z now contains .5 (you have to use 2.0, not 2)
Notes and Warnings
If doing math with floats, you need to add a decimal point, otherwise it will be treated as an int. See the Floating point constants page for details.

But i can’t seem to have the compiler include the .0: it simply doesnt see it.

In my original application i need the fraction part, when i copy and paste the preview code into IDE and manually add the .0 my application works fine, but that kinda defeats the purpose of mblock :slight_smile:

Any suggestions?


#2

@babylon_nl the block is designed to take a number and so it auto rounds (removing the .). That shouldn’t happen on the Arduino Code, this is a bug. I’ll report it, but it might be a while until something happens. In the meantime, I’ll try to create an extension to fix the issue.

Good luck!


#3

Thanks @Best_codes for confirming this, i’ll stop worrying about it than, i’ve tried to work with the extensionmaker, but I get hopelessly lost in the symantics, I’m really looking forward to your extension and be happy to implement it!


#4

Great! We’ll see if my extension of mBlock’s fix comes first. Sometimes it takes a few weeks for an extension to be reviewed.


#5

Great, @Best_codes, will you let us know what the extension will be named? Thanks a lot!


#6

I sure will. Might take me a bit to get started on it…