Home > Back-end >  O great god solve the issue of a decimal point
O great god solve the issue of a decimal point

Time:10-07

First post code
Try
{
If (StringGrid1 - & gt; Cells [6] [ARow]!="" & amp; & StringGrid1 - & gt; Cells [5] [ARow]!="")
{
Currency GoodsCount, GoodsPrice;
GoodsCount=RoundTo (StringGrid1 - & gt; Cells [5] [ARow] ToDouble (), 4);
GoodsPrice=RoundTo (StringGrid1 - & gt; Cells [6] [ARow] ToDouble (), 4);
StringGrid1 - & gt; Cells [7] [ARow]=CurrToStr (GoodsCount * GoodsPrice);
}
}
The catch (Exception & amp; The exception)
{
;
}

Development environment is c + + build 2007 controls is TStringGrid when the fifth column and column 6 input value is larger (5.6 column is an integer type), 7 column calculating a decimal point, even if StringGrid1 - & gt; Cells [7] [ARow]=RoundTo (GoodsCount * GoodsPrice) is invalid, or a decimal point, tried various methods, don't know the cause of the problem, a great god give prompt, to train of thought

CodePudding user response:

Decimal point is not always occur, occasional, probability event, very depressed

CodePudding user response:

I guess not decimal, but changed to scientific notation, 5 and 6 are integers, changing CurrToStr to IntToStr try, really can't use sprintf

CodePudding user response:

5.6 also allows the decimal

CodePudding user response:

Then you have to get the value first, then add a judge how much greater than when it into IntToStr with CurrToStr otherwise

CodePudding user response:

You can use this kind of Currency, Currency is the header file & lt; Syscurr. H> , accurate to small value after four, but it is a 64 - bit integer

CodePudding user response:

Currency is accurate to four decimal point, but the problem is should not be came a decimal point, the effect is shown in figure

CodePudding user response:

Don't you want to use the integer no decimal point?

CodePudding user response:

refer to 6th floor a516478314 response:
Currency is accurate to four decimal point, but the problem is should not be came a decimal point, the effect is shown in figure

Sweat, namely however are all integers, doing with double calculation

CodePudding user response:

Arguably Currency not, floating point Numbers it is easier to appear, you are there look at all these values using the viewer to see is how much, because I tried you 297 * 38 this won't appear,

CodePudding user response:

refer to the eighth floor zdhsoft response:
Quote: refer to the sixth floor a516478314 response:

Currency is accurate to four decimal point, but the problem is should not be came a decimal point, the effect is shown in figure

Sweat, namely however are all integers, doing with double


This is just one example, case is all integers, but the reality is this way can also fill in decimal

CodePudding user response:

references 9 f jAmEs_ response:
arguably Currency not, floating point Numbers it is easier to appear, you are there look at all these values using the viewer to see is how much, because I've tried 297 * 38 this won't appear, you


His computer is no problem, testing is not to come out, and not all use the software will be a problem, some users will appear, and some users would not be executed must also go wrong

CodePudding user response:

With the INT

CodePudding user response:

Binary decimal conversion between decimal fraction and accuracy problems, Suggestions to set up a small threshold, such as 0.0001, if a numerical value is less than the threshold value after the decimal point, is converted to an integer and then output

CodePudding user response:

Another way is internally with all the value of the integer representation and processing, such as not in yuan as the unit, but with points or smaller unit to represent and calculation, so that all values are integers, only at the time of output, then convert into a floating point number
  • Related