Jump to content
abdellahmehdi

Types incompatibles : 'string' et 'Extended'

Recommended Posts

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 by Remy Lebeau
  • Thanks 1

Share this post


Link to post
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. 

 

 

  • Thanks 1

Share this post


Link to post
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 by Remy Lebeau
  • Like 1
  • Thanks 1

Share this post


Link to post
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×