0

I am using Oracle9i and NHibernate 3.1.0.4 and FluentNhibernate 1.2.0.712

NHibernate is configured as follows...

<property name="dialect">NHibernate.Dialect.Oracle9iDialect</property>
      <property name="connection.driver_class">NHibernate.Driver.OracleClientDriver</property>
      <property name="connection.connection_string">Data Source=ORA9TEST;User ID=NOPE;Password=NOPE;</property>
      <property name="query.substitutions">true=1;false=0</property>
      <property name="show_sql">true</property>

It generates this insert statemanet

2012-08-10 16:33:36,380 [DEBUG] 15  NHibernate.SQL                      - 

INSERT INTO FACT_Data (STime, subg_number, subg_index, measurement, Rj, InvalidSpec, data_uid, WrittenState, dept_id, specs_id, data_id) VALUES (:p0, :p1, :p2, :p3, :p4, :p5, :p6, :p7, :p8, :p9, :p10);:p0 = 2/7/2012 12:49:57 AM [Type: DateTime (0)], :p1 = 103 [Type: Int32 (0)], :p2 = 0 [Type: Int32 (0)], :p3 = 30.346 [Type: Single (0)], :p4 = 0 [Type: Single (0)], :p5 = False [Type: Boolean (0)], :p6 = 0 [Type: Int32 (0)], :p7 = 0 [Type: Int32 (0)], :p8 = 2 [Type: Int32 (0)], :p9 = 45423 [Type: Int32 (0)], :p10 = 1178436 [Type: Int32 (0)]

The Column FACT_Data.Measurement is type NUMBER(*,6)

When I read that row back out, instead of the Measurement value being 30.346 it is 30.346001. What can I do to make it store my Single value correctly without the extra 0.000001?

Please and thank you

Eggi
  • 1,684
  • 4
  • 20
  • 31
MrSethT
  • 43
  • 6

1 Answers1

1

You should use Decimal instead of Single if you need this kind of precision.

You can find more information about floating point types here: decimal vs double! - Which one should I use and when?

Community
  • 1
  • 1
Eggi
  • 1,684
  • 4
  • 20
  • 31
  • In the Oracle I have, 9i, DECIMAL(*,6) is the same as NUMBER(*,6). Using that, I get the same results "30.346001"... – MrSethT Aug 13 '12 at 13:17
  • 1
    I meant in your .net application. You should use the Decimal type there. In Oracle it makes no difference. – Eggi Aug 13 '12 at 13:20
  • That looks like it did it, but what is the (best) matching datatype in Oracle for Decimal, FLOAT or NUMBER? – MrSethT Aug 14 '12 at 18:40
  • Data types in oracle: http://ss64.com/ora/syntax-datatypes.html. FLOAT is just a synonym for the NUMBER type. So it is the same. Decimal Type in .net: http://msdn.microsoft.com/en-us/library/364x0z75(v=vs.80).aspx ... that means it would not make sense to create numbers in oracle with a higher precision than the one of a Decimal (if you use a Decimal). – Eggi Aug 14 '12 at 18:49