[RESOLVED] round not rounding in CRX
Hello all. I have this function to convert to scientific notation:
Code:
Function (StringVar dInput)
local NumberVar iCount := 0;
local NumberVar dCurrent := cdbl(dInput);
local StringVar sReturn := "";
//dcurrent := dinput
while (dCurrent<-10 or dCurrent>10) do
(
dcurrent := dcurrent /10 ;
iCount := iCount+1;
);
round(dCurrent, 1) & "E" & sgn(dInput) * int(iCount);
The function works great, only problem is that I get something like "3.4E3.00" instead of "3.4E3".
Any reason why that anyone can think of?
Re: round not rounding in CRX
Try :
Code:
ToText(round(dCurrent, 1),2) & "E" & ToText(sgn(dInput) * int(iCount),0);
or
Code:
ToText(round(dCurrent, 1)) & "E" & ToText(sgn(dInput) * int(iCount),0);
Re: round not rounding in CRX
Looks like your problem is sgn(dInput) * int(iCount); showing decimals, not the Round function. Not sure why but try to piece out that part and see what happens with just parts of the line before you build it up again.
Re: round not rounding in CRX
but why when the string concatenate does the first part of the output have decimals then?
Re: round not rounding in CRX
When you issued the command
You asked it to round to 1 decimal place. So you got it rounding to 3.4 according to your example.
Re: round not rounding in CRX
Ah. I must have mistyped. for, say, 34000 with my routine I get 3.40E8.00. This obviously isn't scientific notation. I'm going to try the recommendations here and get back to you.
Re: round not rounding in CRX
jggtz, your examples helped, but didn't completely solve the problem. Somehow, they fixed the "E2.00" part of the improper result, but now I still have 3.40E2" as a decimal. I'm like to only see this rounded to one decimal place.
As I was typing this I changed this:
Code:
ToText(round(dCurrent, 1),2) & "E" & ToText(sgn(cdbl(dInput)) * int(iCount),0);
to this:
Code:
ToText(round(dCurrent, 1),1) & "E" & ToText(sgn(cdbl(dInput)) * int(iCount),0);
and it fixed the problem. Thanks a lot.
Re: [RESOLVED] round not rounding in CRX
I think that you shouldn't restrict the decimals in the left side of the number
5 723 400 000 ----> 5.7234E9 Is correct
5 723 400 000 ----> 5.7E9 Is NOT correct
Re: [RESOLVED] round not rounding in CRX
I agree, however I'm implementing scientific notation for the sake of space. In my other elements of my program (a log for instance) the scientific notation values are all rounded to the nearest tenth, so I'm sticking with it for consistency.