/* * MathPlanner 3.1 - Mathematical design tool. * Copyright(C) 2002 Jarmo Nikkanen * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation. * * You should have received a copy of the GNU General Public License with this program. * */ #include #include #include "Error.h" QString mpl_real2text_dec(double real,int digits) { QString st; double v=fabs(real); int i,n,x; if (v>1.0) n=(int)floor(log10(v))+1; else n=1; i=digits-n; if (i<0) i=0; st.setNum((double)real,'f',i); x=st.length()-1; for(;x>=0;x--) if (st.at(x)!='0' || x==0) { if (st.at(x)=='.') st.truncate(x); else st.truncate(x+1); break; //x=0; } return(st); } QString mpl_real2text_frac(double real,int digits,bool mode) { QString st; double v=fabs(real); if (v==0.0) v=1.0; double exponent=floor(log10(v)); if (mode) exponent=floor(exponent/3)*3; double frac=real/pow(10.0,exponent); st=mpl_real2text_dec(frac,digits); return(st); } QString mpl_real2text_exp(double real,bool mode) { QString st; double v=fabs(real); if (v==0.0) v=1.0; double exponent=floor(log10(v)); if (mode) exponent=floor(exponent/3)*3; st=mpl_real2text_dec(exponent,0); return(st); }