joeferner / node-oracle

node.js driver to connect with an oracle database.
MIT License
271 stars 99 forks source link

setNumberStringFormat introduction #245

Open denis-salgon opened 9 years ago

denis-salgon commented 9 years ago

hi, My need is to have decimal values like it are in the database without any alteration due to the approximation. For example : In a database number field, I could have : 249,199999999998 249,19999999998 249,1999999998 When i try to retrieved it from the database, i get in JS number 249.19999999999803 249.19999999998 249.19999999979999 Well, the result is not safe. The most safe solution is to retrieve it as string. So, I introduced setNumberStringFormat option for the connection object . You can set format for decimal number as "99999999999999.99999999999999" for example.

cnx.setNumberStringFormat( "99999999999999.99999999999999" );

When it is set, number value are retrieved as string without alteration : 249,19999999999800 249,19999999998000 249,19999999980000 That's allow me to transform these string values in my own javascript BCD format. I splited integer type (Integer/smallint) from the other number types, but, it's not usefull because oracle create smallint and integer as number(38) type. It's possible to switch off the option by assigning an empty string in format. cnx.setNumberStringFormat("");

Thanks to watch my request