Purpose You want to convert a floating point number to decimal Some SAP tables contain values in floating point format. When you read such tables with; for example, /guixt/dbselect, a number in floating point notation is returned, e.g. "1.5301000000000000E+03" or with a comma as decimal separator "1,5301800000000000E+03". For further calculations and comparisons in GuiXT you need the decimal representation of the number. |
Solution // convert a number from floating point format to decimal format // option: specify fixed number of decimals function Float2Dec(x,fixdec) { var deccomma =x.indexOf(',') > -1; if (deccomma) { x = x.replace(",", "."); }; if (isNaN(parseFloat(x))) { return 0; } var result; if (fixdec) { result = parseFloat(x).toFixed(fixdec); } else { result = parseFloat(parseFloat(x).toFixed(8)).toString() ; }; if (deccomma) { result= result.replace(".", ","); }; return result; }; Examples Set V[f1] "1.5301800000000000E+03" CallJS f2 = Float2Dec &V[f1] // Test message Message "&V[f2]" ![]() Set V[f1] "1.5301800000000000E+03" CallJS f2 = Float2Dec &V[f1] 1 ... ![]() Set V[f1] "1.5301800000000000E+03" CallJS f2 = Float2Dec &V[f1] 5 ... ![]() Set V[f1] "1.5301805600E+03" CallJS f2 = Float2Dec &V[f1] ... ![]() |
Components |