Custom rounding and scientific notation for HP 48GX
This routine starts by checking if the input number is already in scientific (SCI) / engineering (ENG) format, which is indicated by the presence of an “E” in its string representation, otherwise it assumes it is a standard format (STD).
IF N \->STR "E" POS
If the number is in SCI/ENG format, the routine extracts the mantissa, rounds it to the specified number of decimal places, and then reconstructs the number in its original notation.
N MANT R TRNC
For numbers in standard (STD) format, the algorithm separates the decimal part, rounds it according to the desired precision, and then recombines it with the integer part to maintain accuracy.
N N 0 TRNC - DUP XPON SWAP MANT R 1 - RND SWAP 10 SWAP ^ * N 0 TRNC + MANT
Finally, it constructs the number’s string representation in scientific notation and converts this back into a number format for further calculations or display.
For those interested in exploring this routine further or incorporating it into their projects, I invite you to visit my GitHub repository here where you can find the routine.