LOCAL nDec AS System.Double oppure AS FLOAT oppure AS System.Decimal
nDec := (56/39)
torna sempre 1 e non 1,43.... grazie
Danilo
Cosa sbaglio?
Moderator: wriedmann
Cosa sbaglio?
maybe my attempt will help
LOCAL nDec as Decimal
nDec:=(57./36.)
return 1.46
Juraj
LOCAL nDec as Decimal
nDec:=(57./36.)
return 1.46
Juraj
Cosa sbaglio?
Works, if you write either number with a ".0"
But this is certainly a bug
But this is certainly a bug
Regards
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
Cosa sbaglio?
Ciao Danilo,
Juraj is right.
"57" e "39" sono considerati tipo integer, perciò il risultato sarà int, se non imposti /vo12 ("Integer divisions return float").
Altra possibilità:
Vedi: https://docs.xsharp.it/doku.php?id=literals
Saluti
Wolfgang
Juraj is right.
"57" e "39" sono considerati tipo integer, perciò il risultato sarà int, se non imposti /vo12 ("Integer divisions return float").
Altra possibilità:
Code: Select all
nDec := (56d/39d)
nDec := (56m/39m)
Saluti
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
Cosa sbaglio?
just one with a dot (57./39) or (57/39.) return 1.46
Cosa sbaglio?
Hi Karl,
this is not a bug. If the /vo12 compiler option is not selected, every division by integers return an integer.
VO behaves the same.
Wolfgang
this is not a bug. If the /vo12 compiler option is not selected, every division by integers return an integer.
VO behaves the same.
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
Cosa sbaglio?
Wolfgang,
i see. Hadn't thought that this may be the case even in core
And, as i just found out, it does not. Setting /vo12 makes the compile fail.
For reference tried in c#, the results are the same. So, it's one of these pitfalls, one has to keep in mind....
I think, i'd prefer the opposite behaviour as default, as i can't think of a lot of showcases, where one works on literal ints and wants to get the truncated result. But that's just me
i see. Hadn't thought that this may be the case even in core
And, as i just found out, it does not. Setting /vo12 makes the compile fail.
For reference tried in c#, the results are the same. So, it's one of these pitfalls, one has to keep in mind....
I think, i'd prefer the opposite behaviour as default, as i can't think of a lot of showcases, where one works on literal ints and wants to get the truncated result. But that's just me
Regards
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
-
- Posts: 774
- Joined: Wed May 17, 2017 8:50 am
- Location: Germany
Cosa sbaglio?
funny, i firstly thought my cpu is defect, until i´ve noticed that there are different division that cause of course different results
(56/39)
(57./36.)
(57./39)
here´s another float result option
? (decimal) 56/39
? (double) 56/39
? (FLOAT) 56/39
regards
Karl-Heinz
(56/39)
(57./36.)
(57./39)
here´s another float result option
? (decimal) 56/39
? (double) 56/39
? (FLOAT) 56/39
regards
Karl-Heinz
- softdevo@tiscali.it
- Posts: 191
- Joined: Wed Sep 30, 2015 1:30 pm
Cosa sbaglio?
Thanks to all
Danilo
Danilo
Cosa sbaglio?
Hi Karl,
But compatibility is important, and changing it would break really a lot of code.
And I can understand why /vo12 makes the compile fail on Core dialect: there is no float datatype.
Wolfgang
so the behaviour of C# is the same as VO and X#.... I would also prefer to have the same as default - had similar problems several times in my VO applications, and therefore I'm always writing numeric literals with decimal point and 0 when dividing, and casting integer variables to float.And, as i just found out, it does not. Setting /vo12 makes the compile fail.
For reference tried in c#, the results are the same. So, it's one of these pitfalls, one has to keep in mind....
I think, i'd prefer the opposite behaviour as default, as i can't think of a lot of showcases, where one works on literal ints and wants to get the truncated result. But that's just me
But compatibility is important, and changing it would break really a lot of code.
And I can understand why /vo12 makes the compile fail on Core dialect: there is no float datatype.
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it