Decimals not Working in Functions
Blitz3D Forums/Blitz3D Beginners Area/Decimals not Working in Functions
| ||
| When I try to use a variable with a decimal value(in a function), it is rounded to the nearest integer. If I need to I can assign integer values and multiply by decimals, but that's not very convenient. Is there a better way? |
| ||
| On your first declaration you have to tell the compiler that that you are using floats from then on you can reference the variable without the # local R#=0 in function calls you have to do the same... This(0.01) Function This(r#) print r# end function |
| ||
| Thank you! That was exactly the kind of thing I was looking for. |
| ||
| Something else to bear in mind with floats, is that if any of the values in a math expression are float values, then the expression will be evaluated as a float expression. |
| ||
| Also, if you want to return a float from a function, you need to declare the function return type. This won't work: Print myFunc(3.14) Function myFunc(n#) Return n End Function This will: Print myFunc(3.14) Function myFunc#(n#) Return n End Function |
| ||
| You can also, retrieve any integer argument as a float if you are actually working with integers but need a float: [code] myFloat#=(Float#(Integer_A%) / (Float#(Integer_B%))) |
| ||
| You only need one side (doesn't matter which) to be cast as a float. |