Home > Back-end >  Trunc very strange question.
Trunc very strange question.

Time:09-16


Trunc (0.7/0.1)=7 the normal

But if the variables defined as
0.7Such as ss: double;
Ss:=0.7;
Trunc (ss/0.1)=6??????
How can you ask properly 7?

CodePudding user response:

Is 0.6

0.7 the scientific notation when values are generally showed 0.6 xxxxcccxxcxE

CodePudding user response:

The ideal way is, as far as possible, using integer as your topic:

(ss * trunc (10)/(0.1 * 10))

So close to the real results you want

CodePudding user response:

Not surprisingly, this is trunc, not round, round in the IEEE754 standard also defines five rounding algorithm, trunc a number, if the number of binary floating-point decimal value cannot accurately said, j may produce larger error,
Delphi, if required high precision floating point arithmetic, 1 TBcd type, can be used to represent up to 64 decimal number (integer + decimal), starting from the D6 have TBcd algorithm library, if requiring the performance is not recommended, you can use third party operation of large Numbers of libraries, such as MPArith BigFloat, such as

CodePudding user response:

This is a Double precision:
Ss: double;
Ss:=0.7;
In fact of the SS value is 0.6999999999999
So, trunc (ss/0.1) is 0.699999999999999/0.1, nature is 6.9999999...

CodePudding user response:

Thank you, it is as you say, but how to express it, but for the ss to write the rounding also not line, molecular denominator are multiplied 100 times also not line,
Can't ss: double;
Ss:=0.7;
Trunc (ss + 0.00000001)/(0.1)=this is can, turnc molecules to add a 0.00000001???????

CodePudding user response:

CodePudding user response:

reference 5 floor sgjie reply:
thank you, it is as you say, but how to express it, but for the ss to write the rounding also not line, molecular denominator are multiplied 100 times also not line,
Can't ss: double;
Ss:=0.7;
Trunc (ss + 0.00000001)/(0.1)=this is can, turnc molecules to add a 0.00000001???????


In front of the said can use TBcd:
USES Data. FmtBcd;
Var
D: double;
//...
D:=double (TBcd (' 0.7 ')/TBcd (' 0.1 '));

CodePudding user response:

reference 5 floor sgjie reply:
thank you, it is as you say, but how to express it, but for the ss to write the rounding also not line, molecular denominator are multiplied 100 times also not line,
Can't ss: double;
Ss:=0.7;
Trunc (ss + 0.00000001)/(0.1)=this is can, turnc molecules to add a 0.00000001???????


This can use a more stupid method
Will DOUBLE to a string and then convert
FloatToStr (StrToFloat (FloatToStr (ss))/0.1);//this can get 7

In fact, that there is no direct relationship with TRUNC function, scientific numeration of Double key system lead to error

CodePudding user response:

Trunc is directly down the decimal

CodePudding user response:

(0.7 + 0.1/2)/0.1

CodePudding user response:

You use the Round replace
Trunc is truncated directly

CodePudding user response:

It seems
1. Do you know about Trunc and Round not what meaning ah,
2. You don't understand the performance of floating point values in memory,

So you need to know:
Trunc, is only is rounded, not consider the decimal places, so 6.9999999 is 6. Use the Round is 7
2. The number of floating point values is approximate in memory, using floating-point calculations, pay attention to the boundary value problem, can appear when extreme=# doesn't work, left and right sides clearly when you debug monitor value, but is not equal, this kind of problem a lot of a lot of, reason is that the number of floating point values is approximate in memory, you must know the principle, to avoid,
  • Related