Hi Boki
Are you aware of the fact that the AsInteger method on NextGrid, NxNumberEdit, NxSpinEdit etc uses Round() to get the Integer value?
Example:
(3.4).AsInteger = 3
(3.5).AsInteger = 4
I would have expected (X).AsInteger = Trunc(X)
If this is by design then it is fine, as long as you are aware of it. It caught me by surprise
Regards,
Deon
AsInteger Methods
Started by deonvn, Jul 20 2007 01:57 PM
5 replies to this topic
#1
Posted 20 July 2007 - 01:57 PM
#2
Posted 20 July 2007 - 02:27 PM
Hello Deon,
I have made it like this. But, maybe a better will be to have property for setting RoundMode (lower, nearest...).
Best regards
I have made it like this. But, maybe a better will be to have property for setting RoundMode (lower, nearest...).
Best regards
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.
#3
Posted 20 July 2007 - 03:47 PM
Where will this property be used?
If it is only used to round AsInteger then it is not really worth it to add a new property just for that.
I would suggest that you stick to the standard expected behaviour, and leave the rest up to the programmer. As far as I can remember the standard DB behaviour for AsInteger is Trunc(X).
If the programmer wants a rounded value he can still use Round(X.AsFloat), or RoundTo(X.AsFloat,-2) or Trunc(X.AsFloat) or whatever...
Regards,
Deon
If it is only used to round AsInteger then it is not really worth it to add a new property just for that.
I would suggest that you stick to the standard expected behaviour, and leave the rest up to the programmer. As far as I can remember the standard DB behaviour for AsInteger is Trunc(X).
If the programmer wants a rounded value he can still use Round(X.AsFloat), or RoundTo(X.AsFloat,-2) or Trunc(X.AsFloat) or whatever...
Regards,
Deon
#4
Posted 20 July 2007 - 04:04 PM
Hello Deon,
I think that this is expected behaviour. You may allways call SetRoundingMode before calling AsInteger. This function include rmTruncate as parameter too.
Best regards
I think that this is expected behaviour. You may allways call SetRoundingMode before calling AsInteger. This function include rmTruncate as parameter too.
Best regards
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.
#5
Posted 20 July 2007 - 04:25 PM
If that is the standard behaviour for AsInteger then it's fine. As long as I know what to expect I can code around it.
Regards,
Deon
Regards,
Deon
#6
Posted 20 July 2007 - 04:46 PM
Hello Deon,
Calling Delphi's SetRoundingMode may give you big flexibility, better than only calling Trunc.
Best regards
Calling Delphi's SetRoundingMode may give you big flexibility, better than only calling Trunc.
Best regards
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users