简体   繁体   English

普及型VAccess控件v双重数据类型

[英]Pervasive VAccess control v double data type

Hope someone can help! 希望有人能帮忙! We're encountering an issue with the Pervasive VAccess control whereby any time we save an item of type 'double' into a Pervasive database, the value saved is different to the one we want... 我们遇到了Pervasive VAccess控件的问题,该问题每次将“ double”类型的项目保存到Pervasive数据库中时,保存的值就与我们想要的值不同...

As an example we try to save 1.44 and it actually saves 1.44004035454 例如,我们尝试保存1.44 ,而实际上保存1.44004035454

A slight difference but a difference nonetheless! 稍有差异,但仍有所不同!

FYI the field defined in the DDF has decimal set to 0, i'm wondering if one course of action is to set this to eg 4? 仅供参考,在DDF中定义的字段的十进制设置为0,我想知道是否有一种行动方法是将其设置为例如4? But thought i'd see if anyone can shed any light on it before we head down that path... 但是以为我会看看是否有人可以在我们走这条路之前对此有所了解...

The underlying effect is nothing to do with pervasive, it's a simple floating point issue . 潜在的影响与普遍性无关,这是一个简单的浮点问题 You'll find the same in any system that uses single- or double-precision floating point, though some systems do automatic rounding to hide this from you. 您会在使用单精度或双精度浮点的任何系统中找到相同的结果,尽管某些系统会自动舍入以将其隐藏起来。

See http://en.wikipedia.org/wiki/Floating_point 参见http://en.wikipedia.org/wiki/Floating_point

In the case of PostgreSQL and its derivatives, you can set extra_float_digits to control this rounding. 对于PostgreSQL及其派生类,可以设置extra_float_digits来控制此舍入。

regress=> SET extra_float_digits = 3;
SET
regress=> SELECT FLOAT8 '1.44';
       float8        
---------------------
 1.43999999999999995
(1 row)

regress=> SET extra_float_digits = 0;
SET
regress=> SELECT FLOAT8 '1.44';
 float8 
--------
   1.44
(1 row)

It defaults to 0, but your client driver might be changing it. 默认为0,但是您的客户端驱动程序可能正在更改它。 If you're using JDBC (which I'm guessing you are) then don't mess with this setting, the JDBC driver expects it to remain how the driver sets it and will get upset at you if you change it. 如果您使用的是JDBC(我想您是这样),那么请不要打扰此设置,JDBC驱动程序希望它保持驱动程序的设置方式,并且如果您更改它,将会感到不高兴。

In general, if you want a human-readable formatted number you should be doing the rounding with round or to_char , or doing it client-side, instead. 通常,如果您想要一个人类可读的格式化数字,则应该使用roundto_char进行四舍五入,或者在客户端进行。 Note that there's no round(double precision, integer) function for reasons explained in answers to this question . 请注意,由于此问题的答案中所述的原因round(double precision, integer)没有round(double precision, integer)函数。 So you'll probably want to_char , eg. 因此,您可能想要to_char ,例如。

regress=> SELECT to_char(FLOAT8 '1.44', 'MI999999999D99');
    to_char    
---------------
          1.44
(1 row)

(I wish PostgreSQL exposed a version of the cast from float8 to text that let you specify extra_float_digits on a per-call basis. That's often closer to what people really want. Guess I should add that if I get the time...) (我希望PostgreSQL公开从float8text ,让您extra_float_digits在每次调用的基础上指定extra_float_digits 。这通常更接近人们的实际需求。如果有时间,我应该补充一点……)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM