I am trying to create a measurement converter, I have seen the tutorial to use the math blocks and I still do not understand
(I do not know what would be the most correct if you use text input or label, according to the tutorial it would be label but I think that I should use text input and leave it empty)
What I would like to achieve is to leave some spaces empty so that you can write the numbers to calculate or if I can not create that, then do a drop-down
Once you put the numbers, click on a button and the app calculate it (I know how to do a button!)
The app would have to make three formulas to give the result, what I do not know is if those three formulas would have to indicate all of them with math blocks or create different text input or labels to be able to indicate what actions have to be performed but putting them in not visible to that do not appear.
A text input makes more sense, since it is associated with input, and would even pop up the device keyboard.
With a label, you still need to have ANOTHER component to enter the value to be converted.
I tried to do it with the text input but I do not know how to use the math block correctly.
The blocks are for example 1 + 1 and what I need is to replace those numbers with those that are entered in the text input.
I think I should put When Button click do and insert the three formulas together, but I do not know how to put is that the third formula is a division of the first and second
Thanks for your help, I’ve finally been able to make everything work well!
But I have one last doubt, the result that appears has 16 decimals, I have seen a block called round, I have put it in before the math blocks but it does not work.
Pressing the “Calcular” button (I’m Spanish, it means Calculate), the text input called “Resultado” shows the result of the two operations that are written in the other text input, that result is the one that I want to round.
Maybe the simplest way to do it would be what @CBVG proposes but I do not know how to put the multiplication, rounding and division.
I have to create a group of new blocks or I should add them to the group of blocks that I already have created and wherei?
Thank you very much for the help you are giving to me
The roundToPlaces function is one possible generalization of this function. You call it by specifying the value that needs rounding off (which could also be a variable; it can even be “myvalue” in the example, which would end up replacing myvalue with a rounded off version of itself) and the number of places you want to retain. Put a 2 as “places” and it will round off to the nearest 100th. Put 0, and it will round off to the nearest integer. Put -1, and it will round off to the nearest 10 (i.e. 37.123 would round to 40).
The number of places is internally rounded in the function as well, to avoid the issue of someone putting 2.3 in there, which would mathematically work, but would return completely silly looking results.
For what you have explained to me I must indicate a value to be rounded with the function.
I have indicated in the function to return the text input “Resultado” (result) with the rounding, “Resultado” replaces Value in your example and in Places I put 2 but still do nothing.
I think the problem is that in your example some variables are created to replace my text input, but I tried to create variables and I could not.
Maybe that’s why in Functions I see “RoundToPlaces” but not apears “with” and can´t put the two variables of your example.
First thing, you do not need to round “2” if you put 2. In fact , you do not need to use 10^, this was there only to allow generalization, where you supply the value and the number of places as input to the function.
If you want to round to the nearest 1/100th, then you can divide by 100 and multiply by 100.
Then, there is a philosophical issue with using Resultado.Text as a variable. It is not a variable, it is a formatted field. Resultado comes with a lot of luggage (font size, background colour, positioning and dimension properties) and each time you are changing anything in this kind of field, you are calling a LOT of behind the scene operations. The idea is that while you are dealing with math, keep it simple and use math variables. AFTER you are finished with the number operation, THEN you are putting the result in Resultado.Text
That said, if those are all your blocks, where is the call to “roundToPlaces”?
It is not going to call itself just because it is defined.
You noticed that I made it use of the arguments, that way it can be used in line. And it returns a value, that means roundToPlaces does not change anything but itself, so it returns a value.
In this example, you put whatever equation you used to feed Resultado, the difference is that it has to go through the roundToPlaces as an argument, along with the number of places. Again, if you will always round only to 2, you can make the procedure simpler by multiplying and dividing by 100, and removing the second argument by clicking on the blue gear and dragging it out.
When you click on the Calcular (Calculate) button, the text input Resultado (Result) will show the result of the formula and the function block returns the result with the round that is the variable Calculado multiplied and divided by 100 to simplify because I want to always round to 2 decimals, and this will should give a result with two decimals … but now the result is always 0!