Post Reply 
ENG button in Casio calculator
12-12-2017, 05:45 PM (This post was last modified: 12-12-2017 05:46 PM by salvomic.)
Post: #19
RE: ENG button in Casio calculator
A new version that should eliminate all leading zeros in ENGA(), ENGB() and prefix().
It remains always the comma first of the E symbol, but it shouldn't be a problem, as the number can be returned again using reeng().
Thanks to cclinus for the original program!

The code:
Code:

// Program to toggle between  ←ENG and ENG→
// define keys / * + (toggle_eng_float)

reeng();

EXPORT ENGA(x)
BEGIN
LOCAL pos,s,i;
IF TYPE(x)==0 THEN
RETURN STRING(x,4,11);
END;

IF (TYPE(x)==2) THEN
  IF (INSTRING(x," ")) THEN x:= reeng(x); END;
END;

IF (TYPE(x)==2) AND (INSTRING(x,"ᴇ24")) THEN
RETURN x;
END;
IF (TYPE(x)==2) AND (INSTRING(x,"ᴇ24")==0) THEN
s:=x;
FOR i FROM 1 TO 3 DO
pos:=INSTRING(s,".");
s(pos):=s(pos-1);
s(pos-1):=".";
IF pos==2 THEN
s:="0"+s;
END;
END;
WHILE INSTRING(s,"0ᴇ") DO
s:=REPLACE(s,"0ᴇ","ᴇ")
END;
//
s:=REPLACE(s,"ᴇ21","ᴇ24");
s:=REPLACE(s,"ᴇ18","ᴇ21");
s:=REPLACE(s,"ᴇ15","ᴇ18");
s:=REPLACE(s,"ᴇ12","ᴇ15");
s:=REPLACE(s,"ᴇ9","ᴇ12");
s:=REPLACE(s,"ᴇ6","ᴇ9");
s:=REPLACE(s,"ᴇ3","ᴇ6");
s:=REPLACE(s,"ᴇ0","ᴇ3");
s:=REPLACE(s,"ᴇ−3","ᴇ0");
s:=REPLACE(s,"ᴇ−6","ᴇ−3");
s:=REPLACE(s,"ᴇ−9","ᴇ−6");
s:=REPLACE(s,"ᴇ−12","ᴇ−9");
s:=REPLACE(s,"ᴇ−15","ᴇ−12");
s:=REPLACE(s,"ᴇ−18","ᴇ−15");
s:=REPLACE(s,"ᴇ−21","ᴇ−18");
s:=REPLACE(s,"ᴇ−24","ᴇ−21");
RETURN s;
END;
END;

EXPORT ENGB(x)
BEGIN
LOCAL pos,s,i,t;
IF TYPE(x)==0 THEN
t:=STRING(x,4,11);
WHILE INSTRING(t,"0ᴇ") DO
t:=REPLACE(t,"0ᴇ","ᴇ")
END;
RETURN t;
END;

IF (TYPE(x)==2) THEN
  IF (INSTRING(x," ")) THEN x:= reeng(x); END;
END;

IF TYPE(x)==2 AND (INSTRING(x,"ᴇ−24"))THEN
RETURN x;
END;
IF TYPE(x)==2 AND (INSTRING(x,"ᴇ−24")==0)THEN
s:=x;
FOR i FROM 1 TO 3 DO
pos:=INSTRING(s,".");
IF s(pos+1)==7431 THEN
s:=REPLACE(s,".ᴇ","0.ᴇ");
ELSE
s(pos):=s(pos+1);
s(pos+1):=".";
IF (pos==2) AND (s(1)==48) THEN
s:=RIGHT(s,DIM(s)-1);
END;
END;
WHILE INSTRING(s,"0ᴇ") DO
s:=REPLACE(s,"0ᴇ","ᴇ")
END;
END;
//
s:=REPLACE(s,"ᴇ−21","ᴇ−24");
s:=REPLACE(s,"ᴇ−18","ᴇ−21");
s:=REPLACE(s,"ᴇ−15","ᴇ−18");
s:=REPLACE(s,"ᴇ−12","ᴇ−15");
s:=REPLACE(s,"ᴇ−9","ᴇ−12");
s:=REPLACE(s,"ᴇ−6","ᴇ−9");
s:=REPLACE(s,"ᴇ−3","ᴇ−6");
s:=REPLACE(s,"ᴇ0","ᴇ−3");
s:=REPLACE(s,"ᴇ3","ᴇ0");
s:=REPLACE(s,"ᴇ6","ᴇ3");
s:=REPLACE(s,"ᴇ9","ᴇ6");
s:=REPLACE(s,"ᴇ12","ᴇ9");
s:=REPLACE(s,"ᴇ15","ᴇ12");
s:=REPLACE(s,"ᴇ18","ᴇ15");
s:=REPLACE(s,"ᴇ21","ᴇ18");
s:=REPLACE(s,"ᴇ24","ᴇ21");
RETURN s;
END;
END;

EXPORT prefix(s)
BEGIN
LOCAL t;
IF TYPE(s)==0 THEN t:= STRING(s,4,11); ELSE t:= s; END;
WHILE INSTRING(t,"0ᴇ") DO
t:=REPLACE(t,"0ᴇ","ᴇ")
END;
t:=REPLACE(t,"ᴇ−24"," y");
t:=REPLACE(t,"ᴇ−21"," z");
t:=REPLACE(t,"ᴇ−18"," a");
t:=REPLACE(t,"ᴇ−15"," f");
t:=REPLACE(t,"ᴇ−12"," p");
t:=REPLACE(t,"ᴇ−9"," n");
t:=REPLACE(t,"ᴇ−6"," μ");
t:=REPLACE(t,"ᴇ−3"," m");
t:=REPLACE(t,"ᴇ0","");
t:=REPLACE(t,"ᴇ3"," k");
t:=REPLACE(t,"ᴇ6"," M");
t:=REPLACE(t,"ᴇ9"," G");
t:=REPLACE(t,"ᴇ12"," T");
t:=REPLACE(t,"ᴇ15"," P");
t:=REPLACE(t,"ᴇ18"," E");
t:=REPLACE(t,"ᴇ21"," Z");
t:=REPLACE(t,"ᴇ24"," Y");
RETURN t;
END;

EXPORT reeng(s)
BEGIN
LOCAL t;
IF TYPE(s)==0 THEN t:= STRING(s,4,11); ELSE t:= s; END;
t:=REPLACE(t," y","ᴇ−24");
t:=REPLACE(t," z","ᴇ−21");
t:=REPLACE(t," a","ᴇ−18");
t:=REPLACE(t," f","ᴇ−15");
t:=REPLACE(t," p","ᴇ−12");
t:=REPLACE(t," n","ᴇ−9");
t:=REPLACE(t," μ","ᴇ−6");
t:=REPLACE(t," m","ᴇ−3");
t:=REPLACE(t," k","ᴇ3");
t:=REPLACE(t," M","ᴇ6");
t:=REPLACE(t," G","ᴇ9");
t:=REPLACE(t," T","ᴇ12");
t:=REPLACE(t," P","ᴇ15");
t:=REPLACE(t," E","ᴇ18");
t:=REPLACE(t," Z","ᴇ21");
t:=REPLACE(t," Y","ᴇ24");
RETURN t;
END;

The key definition to use the program:
Use Shift-Help (User) and
÷ ENGB()
x ENGA()
- prefix()
+ reeng()
Code:

// this require ENGA(), ENGB(), prefix(), reeng() in a program
KEY K_Mul()
BEGIN
RETURN "ENGA(Ans)";
END;

KEY K_Div()
BEGIN
RETURN "ENGB(Ans)";
END;

KEY K_Plus()
BEGIN
RETURN "EXPR(reeng(Ans))";
END;

KEY K_Minus()
BEGIN
RETURN "prefix(Ans)";
END;

A code to toggle from and to ENG format (key 1: shift-Help 1):
Code:

KEY K_1()
// use Shift Help 1
// HFormat: 0 standard, 1 fixed, 2 scientific, 3 engineering
// 4 floating, 5 rounded
BEGIN
 if HFormat == 0 then
  HFormat:=3;
 else
  HFormat:=0;
 end;
 return "";
END;

Enjoy!

Salvo

∫aL√0mic (IT9CLU) :: HP Prime 50g 41CX 71b 42s 39s 35s 12C 15C - DM42, DM41X - WP34s Prime Soft. Lib
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
ENG button in Casio calculator - cclinus - 10-30-2015, 05:09 PM
RE: ENG button in Casio calculator - epp - 10-30-2015, 07:46 PM
RE: ENG button in Casio calculator - ww63 - 10-12-2017, 02:35 PM
RE: ENG button in Casio calculator - salvomic - 12-12-2017 05:45 PM
RE: ENG button in Casio calculator - Tyann - 01-07-2018, 12:35 PM
RE: ENG button in Casio calculator - Tyann - 01-07-2018, 05:18 PM



User(s) browsing this thread: 2 Guest(s)