乘法时的问题(货币乘以浮动) [英] problems at multiplication (Currency multiplied with float)

查看:99
本文介绍了乘法时的问题(货币乘以浮动)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个与数据类型转换相关的基本问题。我是

将货币乘以浮动数据类型。


fltInterestRate = 1.23333;

curAmount = 91000000;


curInterestAmount = curAmount * fltInterestRate


curInterestAmount应该有112233030


但我得到了112230300(因此我失去了精度在浮点数

变量)。


我试图使用类型转换但是它没有工作并且有编译

错误。


curAmount curInterestAmount是类CCurrency的对象,其

实现是项目的一部分。


任何指针在这种情况下将非常有帮助。

解决方案

abdul_n_k ... @ hotmail.com写道:

我有一个与数据类型转换相关的基本问题。我将货币乘以浮动数据类型。

fltInterestRate = 1.23333;
curAmount = 91000000;

curInterestAmount = curAmount * fltInterestRate

curInterestAmount应该有112233030

但是我得到了112230300(因此我在浮动
变量上失去精度)。

我试图使用类型转换但是它没有工作并且编译错误。

curAmount curInterestAmount是类CCurrency的对象,其实现是项目的一部分。

这个上下文中的任何指针都非常有帮助。




向我们展示CCurrency的实现。


干杯! --M


ab *** *******@hotmail.com 写道:

我有一个与数据类型转换有关的基本问题。我是将货币乘以浮点数据类型。


这是一个简单的规则:不要使用''float''数据类型,除非它绝对是必要的b / b $(如果你不得不问,这不是必需的)。相反,使用

''double''。你的所有问题都会消失。

[...]




V


< BLOCKQUOTE> ||这是一个简单的规则:不要使用''float''数据类型,除非它是

绝对

||必要的(如果你不得不问,这是没有必要的)。相反,

使用

|| ''双''。你的所有问题都会消失。


Vic,除了记忆成为问题的情况外,你同意了。

例如,之前对数据执行FFT / IFFT,每32位整数值的
存储为double。在这里,我们用24字节(双)处理
而对于32位整数处理12字节(浮点数)。

对于7兆字节的数据变得很大。无论如何.........


I have a basic question related to datatype conversion. I am
multiplying currency to float datatype.

fltInterestRate=1.23333;
curAmount = 91000000;

curInterestAmount = curAmount * fltInterestRate

curInterestAmount should have 112233030

But i am getting 112230300 (thus I am loosing precision on the float
variable).

I tried to use typecasting but it didn''t work and got compilation
error.

curAmount curInterestAmount are objects of class CCurrency whose
implementation is part of the project.

Any pointers in this context will be highly helpful.

解决方案

abdul_n_k...@hotmail.com wrote:

I have a basic question related to datatype conversion. I am
multiplying currency to float datatype.

fltInterestRate=1.23333;
curAmount = 91000000;

curInterestAmount = curAmount * fltInterestRate

curInterestAmount should have 112233030

But i am getting 112230300 (thus I am loosing precision on the float
variable).

I tried to use typecasting but it didn''t work and got compilation
error.

curAmount curInterestAmount are objects of class CCurrency whose
implementation is part of the project.

Any pointers in this context will be highly helpful.



Show us the implementation of CCurrency.

Cheers! --M


ab**********@hotmail.com wrote:

I have a basic question related to datatype conversion. I am
multiplying currency to float datatype.
Here is a simple rule: don''t use ''float'' datatype unless it is absolutely
necessary (and if you have to ask, it''s not necessary). Instead, use
''double''. All your problems will go away.
[...]



V


|| Here is a simple rule: don''t use ''float'' datatype unless it is
absolutely
|| necessary (and if you have to ask, it''s not necessary). Instead,
use
|| ''double''. All your problems will go away.

Vic, agreed with you except for cases where ''memory'' becomes a concern.
For instance, prior to performing an FFT/IFFT on data, each 10 bits
of a 32 bit integer value gets stored as double. Here we''re dealing
with 24 bytes (double) versus 12 bytes (float) for a 32 bit integer.
For 7 mebibytes of data that becomes hefty. In any event .........


这篇关于乘法时的问题(货币乘以浮动)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆