1. E notation NOT wanted

Hello
Seltgor here

In the following programme

I enter a 5 digit number and answer is O.K.
Enter e.g. 1233214 and answer is 5.35654 e + 006

A simple number is required not the e stuff

Please, how do I get a simple answer

e.g. number 121 is pal 121 after 0 reversal
or number 123234 is pal after 1 reversal

when answer is 7 numbers or more answer is e stuff
and the original number is also converted to e

So, any clues ??

All was O.K. in old .ex programme

In anticipation

Cheers
Selgor

programme:=

-----------------------------------------PAL 1A ---------- 
 
include Win32Lib.ew 
without warning 
 
sequence seq 
global object input_number,reversed_number,work_number,substitute_number, w, 
       number_of_digits,divisor,first_digit,last_digit,reversals,return_value, 
       equal_fd_ld,pal_zero,zero_to_be,been_here 
 
-------------------------------------------------------------------------------- 
--  Window Window1 
global constant  Window1  = create(Window,"",0,150,150,610,115,{WS_POPUP,WS_DLGFRAME}) 
                                 setWindowBackColor(Window1,Parchment) 
global constant LText1 = createEx( LText, "Type a Number and Enter", Window1, 12, 10, 132, 20, 0, 0 ) 
global constant EditText1 = createEx( EditText, "", Window1, 150, 10, 88, 20, 0, 0 ) 
global constant LText2 = createEx( LText, "Palindrome is ", Window1, 60, 50 , 90, 20, 0, 0 ) 
global constant EditText2 = createEx( EditText, "", Window1, 150, 50, 88, 20, 0, 0 ) 
global constant LText3 = createEx( LText, "Reversals were", Window1, 270, 53, 102, 20, 0, 0 ) 
global constant EditText3 = createEx( EditText, "", Window1, 375, 50, 48, 20, 0, 0 ) 
global constant LText4 = createEx( LText, "Hit Enter to Restart", Window1, 450, 50, 100, 20, 0, 0 ) 
 
global constant LText6 = createEx( LText, "Palindromic Numbers", Window1, 240, 90, 192, 20, 0, 0 ) 
 
------------------------------------------------------------------------------------------------------- 
 global constant LText5 = createEx( LText, "Left Click Window to exit", Window1, 380, 10, 192, 20, 0, 0 ) 
 setFont(LText5,"Times Roman",12,Italic+Bold) 
------------------------------------------------------------------------------------------------------- 
global procedure palindrome() 
 
    seq[2] = work_number 
    seq[3] = reversals 
 
     setText(EditText1,seq[1]) 
     setText(EditText2,seq[2]) 
     setText(EditText3,seq[3]) 
     setVisible(LText4,1) 
end procedure 
 
global function check_for_palindrome() 
    return_value = 0 
    zero_to_be = work_number 
    divisor = 1 
    divisor = power(10,number_of_digits-1) 
    for i = 1 to floor(number_of_digits/2) do 
        first_digit = floor(zero_to_be/divisor) 
        last_digit = remainder(zero_to_be,10) 
            if first_digit = last_digit  then return_value = 1 
                zero_to_be = floor(remainder(zero_to_be,divisor)/10) 
                divisor = floor(divisor/100) 
            else return_value = 0  end if 
    end for 
    return return_value 
end function 
 
global procedure count_the_digits() 
    number_of_digits = 0 
    substitute_number = work_number 
    while substitute_number != 0 do 
        substitute_number = floor(substitute_number/10) 
        number_of_digits = number_of_digits + 1 
    end while 
end procedure 
 
global procedure re_dig() 
    substitute_number = work_number 
    reversed_number = 0 
    while substitute_number != 0  do 
        reversed_number = reversed_number * 10 + 
                          remainder(substitute_number,10) 
        substitute_number = floor(substitute_number/10) 
    end while 
    reversals = reversals + 1 
end procedure 
 
global procedure main() 
    equal_fd_ld = 0 
    pal_zero = 0 
    while equal_fd_ld = 0 and pal_zero = 0 do 
        count_the_digits() 
        re_dig() 
        work_number = work_number + reversed_number 
        count_the_digits() 
        if check_for_palindrome() = 0 then 
            main() 
        end if 
        equal_fd_ld = return_value 
        pal_zero = zero_to_be 
    end while 
    palindrome() 
end procedure 
 
global procedure init_variables_and_get_number_and_check_input_validity() 
    been_here = 0 
    reversals = 0 
    seq = repeat(0,3) 
    input_number=getNumber(EditText1) 
    --input_number = prompt_number("Type a positive number then ENTER \n\n",{}) 
    work_number = input_number 
    seq[1] = input_number 
    count_the_digits() 
    if check_for_palindrome() = 1 then 
        palindrome() 
    else main() 
    end if 
end procedure 
 
 
-------------------------------------------------------------------------------- 
procedure Window1_onActivate (integer self, integer event, sequence params)--params is () 
  setVisible(LText4,0) 
  setVisible(LText6,1) 
 
  setFocus(EditText1) 
end procedure 
setHandler( Window1, w32HActivate, routine_id("Window1_onActivate")) 
-------------------------------------------------------------------------------- 
procedure EditText1_onKeyDown (integer self, integer event, sequence params) 
                  --params is ( atom scanCode, atom shift ) 
   if params[1]=13 then 
       if self=EditText1 then 
 
           doEvents(0) 
 
          init_variables_and_get_number_and_check_input_validity() 
           setFocus(EditText3) 
       elsif self=EditText3 then 
         setText(EditText1,"") 
       setText(EditText2,"") 
        setText(EditText3,"") 
          setVisible(LText4,0) 
 
       end if 
   end if 
 
end procedure 
setHandler( {EditText1,EditText2,EditText3}, w32HKeyDown, routine_id("EditText1_onKeyDown")) 
 
procedure CloseApp ( integer self, integer event, sequence parms ) 
    if self = Window1 then 
       closeWindow(Window1) closeApp() 
    end if 
end procedure 
setHandler(Window1, w32HClick, routine_id("CloseApp")) 
WinMain( Window1,Normal ) 
 
 
new topic     » topic index » view message » categorize

2. Re: E notation NOT wanted

Selgor said...


I enter a 5 digit number and answer is O.K.
Enter e.g. 1233214 and answer is 5.35654 e + 006

A simple number is required not the e stuff

Please, how do I get a simple answer

Replace the appropriate setText() calls with this ...

  setText(somefield, sprintf("%d", somevalue)) 
new topic     » goto parent     » topic index » view message » categorize

3. Re: E notation NOT wanted

Hello Derek

Selgor here

Thank you Derek greatly appreciated

Just where in manual or w32Lib do I find the sprint %d%

I read it in the "old" manual and used printf with %d etc many times

Or should I have just have known using a bit of nous ????

Anyway ....... works fine

This No.12 in the long haul to get 60 odd .ex progs up to .exw

I will probably write you again

Thanks for your patience

Cheers

Selgor

new topic     » goto parent     » topic index » view message » categorize

4. Re: E notation NOT wanted

Selgor said...

Just where in manual or w32Lib do I find the sprint %d%

I read it in the "old" manual and used printf with %d etc many times

In the manual, if you look at printf, you can see at the end of that section a 'see also' for sprintf.

new topic     » goto parent     » topic index » view message » categorize

5. Re: E notation NOT wanted

Thanks Derek
Found
Noted

Cheers

Selgor

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu