Skip to main content

Obliczenia zmiennoprzecinkowe na liczbach całkowitych (makro)

Streszczenie: Dzielenie liczb całkowitych w makrze daje wynik całkowity (np. 5/10 = 0) – aby uzyskać część dziesiętną, wartość trzeba najpierw przepisać do zmiennej typu float (wynik 0,5).
EN: In EasyBuilder macros, integer division truncates; convert to float first to get a decimal result.

Dotyczy: EasyBuilder Pro / EasyBuilder8000 – makra
Źródło: Weintek FAQ (materiały producenta), oryginalny tytuł: „How to do floating point calculations with integers?”

To gain a result with decimal place when dividing integers, please convert the integer to float first. 

Please see the following Macro. D8=5 is the integer value gained from PLC.

Ilustracja: Obliczenia zmiennoprzecinkowe na liczbach całkowitych (makro) – D8=5 is the integer value gained from PLC.

Line 10: Since D8 is an integer, D8/10 is performed as an integer operation and the result is 0. The result is then written to a float variable, float_D8, therefore float_D8 is 0.0.
Line 15: Since temp is a float, temp/10 is performed as a float operation and the result is 0.5.

 

 

Słowa kluczowe

makro, macro, float, liczby zmiennoprzecinkowe, dzielenie, integer division, konwersja typu, liczby całkowite, wynik dziesiętny, How to do floating point calculations with integers?