|
-
May 19th, 2008, 03:09 PM
#1
Thread Starter
Fanatic Member
[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?
-
May 19th, 2008, 10:28 PM
#2
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);
-
May 19th, 2008, 10:34 PM
#3
Hyperactive Member
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.
-
May 20th, 2008, 10:37 AM
#4
Thread Starter
Fanatic Member
Re: round not rounding in CRX
but why when the string concatenate does the first part of the output have decimals then?
-
May 20th, 2008, 09:52 PM
#5
Hyperactive Member
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.
-
May 21st, 2008, 07:54 AM
#6
Thread Starter
Fanatic Member
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.
-
May 21st, 2008, 07:58 AM
#7
Thread Starter
Fanatic Member
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.
-
May 22nd, 2008, 12:13 PM
#8
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
-
May 22nd, 2008, 12:38 PM
#9
Thread Starter
Fanatic Member
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|