Results 1 to 9 of 9

Thread: [RESOLVED] round not rounding in CRX

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2007
    Location
    Middletown, CT
    Posts
    948

    Resolved [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?

  2. #2
    Frenzied Member
    Join Date
    May 2006
    Location
    some place in the cloud
    Posts
    1,886

    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);

  3. #3
    Hyperactive Member
    Join Date
    Jul 2007
    Posts
    479

    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.

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2007
    Location
    Middletown, CT
    Posts
    948

    Re: round not rounding in CRX

    but why when the string concatenate does the first part of the output have decimals then?

  5. #5
    Hyperactive Member
    Join Date
    Jul 2007
    Posts
    479

    Re: round not rounding in CRX

    When you issued the command
    Code:
    round(dCurrent, 1)
    You asked it to round to 1 decimal place. So you got it rounding to 3.4 according to your example.

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2007
    Location
    Middletown, CT
    Posts
    948

    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.

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2007
    Location
    Middletown, CT
    Posts
    948

    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.

  8. #8
    Frenzied Member
    Join Date
    May 2006
    Location
    some place in the cloud
    Posts
    1,886

    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

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2007
    Location
    Middletown, CT
    Posts
    948

    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
  •  



Click Here to Expand Forum to Full Width