Remy Lebeau 1394 Posted July 25, 2022 (edited) You can't perform arithmetic with a Double and a String as operands. You have to first convert the String to a Double/Extended first. Use StrToFloat() or equivalent for that. And then you can convert the result back to a String using FloatToStr() or equivalent. Try something more like this: DBEdit43.Text := FloatToStr(0.000844 * StrToFloat(scGPDBEdit82.Text)); Edited July 25, 2022 by Remy Lebeau 1 Share this post Link to post
Tom F 83 Posted July 25, 2022 1 hour ago, Remy Lebeau said: You can't perform arithmetic with a Double and a String as operands. You have to first convert the String to a Double/Extended first. Use StrToFloat() or equivalent for that. And then you can convert the result back to a String using FloatToStr() or equivalent. Try something more like this: DBEdit43.Text := FloatToStr(0.000844 * StrToFloat(scGPDBEdit82.Text)); Also note, aehimself, that StrToFloat will cause an exception if scGPDBEDit82.Text is not a valid floating point number. To avoid that, you could use https://docwiki.embarcadero.com/Libraries/Alexandria/en/System.SysUtils.StrToFloatDef If the conversion fails, the default is returned instead. 1 Share this post Link to post
Remy Lebeau 1394 Posted July 26, 2022 (edited) 4 hours ago, Tom F said: Also note, aehimself, that StrToFloat will cause an exception if scGPDBEDit82.Text is not a valid floating point number. To avoid that, you could use https://docwiki.embarcadero.com/Libraries/Alexandria/en/System.SysUtils.StrToFloatDef If the conversion fails, the default is returned instead. On the other hand, depending on the situation, it would probably be better not to perform the calculation at all if the input is invalid, in which case TryStrToFloat() would make more sense if you want to avoid the exception and skip the calculation at the same time. Edited July 26, 2022 by Remy Lebeau 1 1 Share this post Link to post
Tom F 83 Posted July 26, 2022 2 minutes ago, Remy Lebeau said: On the other hand, depending on the situation, it would probably be better not to perform the calculation at all if the input is invalid, in which case TryStrToFloat() would make more sense if you want to avoid the exception and skip the calculation at the same time. Thanks for the clarification, Remy. Share this post Link to post