ODBiC Discussion Board


Undoing Scientific Notation

by Kurt Usowski, July 8, 2005 14:22

Below is a function that can help when your ODBC driver insists on returning a number in scientific notation (e.g., 1.2345678E-2) thus turning it into text and fouling up any subsequent math you might want to do with the number. Unfortunately, it loses precision when the exponent is negative, leaving at most 6 decimal places. Maybe someone can tell me why (ODBiC 2.2 on Xitami, Windows XP, MS Access Driver).

<% 
FUNCTION UnSciNot(SciNotNum) coefficient, exponent, index, factor, result;
	SET factor = 1;
	SET coefficient = $SPLIT(SciNotNum,"E");
	SET exponent = $SciNotNum$;
	SET index = ABS($exponent$);
	WHILE $index$ > 0;
		IF $exponent$ > 0;
			SET factor = $factor$*10;
		   ELSE;
			SET factor = $factor$/10;
		   ENDIF;
		SET index = $index$ - 1;
	   ENDWHILE;
	SET result = $coefficient$*$factor$;
	RETURN $result$
%>


Replies:


Post Your Reply:

Name   
E-mail  optional
Topic  
Message:

HTTP Link: 
Link text: 

          


Copyright ©1997-2003, Roger Harris. All rights reserved.