details:   https://code.openbravo.com/erp/devel/pi/rev/34727a4bec62
changeset: 15462:34727a4bec62
user:      Augusto Mauch <augusto.mauch <at> openbravo.com>
date:      Mon Feb 13 16:30:57 2012 +0100
summary:   Fixes issue 14769: to_text function now supports scientific notation

diffstat:

 src-db/database/model/prescript-PostgreSql.sql |  20 +++++++++++++++++---
 1 files changed, 17 insertions(+), 3 deletions(-)

diffs (31 lines):

diff -r e4e3a55d6378 -r 34727a4bec62 
src-db/database/model/prescript-PostgreSql.sql
--- a/src-db/database/model/prescript-PostgreSql.sql    Mon Feb 13 16:00:40 
2012 +0100
+++ b/src-db/database/model/prescript-PostgreSql.sql    Mon Feb 13 16:30:57 
2012 +0100
@@ -166,10 +166,24 @@
 text
 )
 RETURNS NUMERIC AS '
+DECLARE
+  v_Pos INTEGER;
+  v_Mant NUMERIC;
+  v_Exp NUMERIC;
+  v_Res NUMERIC;
 BEGIN
-RETURN to_number($1, ''S99999999999999D9999999999'');
-EXCEPTION 
-  WHEN OTHERS THEN 
+  v_Pos := position(''E'' in upper($1));
+  IF v_Pos = 0 THEN
+    -- this is the old behaviour
+    RETURN to_number($1, ''S99999999999999D999999'');
+  ELSE
+    v_Mant := substring($1 from 1 for v_Pos - 1); -- Mantissa, implicit cast 
to data type NUMERIC
+    v_Exp := substring($1 from v_Pos + 1); -- Exponent, implicit cast to data 
type NUMERIC
+    v_Res := v_Mant * power(10, v_Exp);
+    RETURN v_Res;
+  END IF;
+EXCEPTION
+  WHEN OTHERS THEN
     RETURN NULL;
 END;
 ' LANGUAGE 'plpgsql' IMMUTABLE

------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to