6
{
  :db/id #db/id[:db.part/db]
  :db/ident :outcome/weighting
  :db/valueType :db.type/float
  :db/cardinality :db.cardinality/one
  :db.install/_attribute :db.part/db 
}

I get an error when I try and add 1 to the entity.

:message "java.lang.IllegalArgumentException: :db.error/wrong-type-for-attribute Value 1 is not a valid :float for attribute :outcome/weighting"

It works fine if I pass in 1.0.

I appreciate that (= (float? 1) false) but is there any other way I can avoid this via Datomic settings without parsing the incoming EDN and adjusting from 1 to 1.0?

bfontaine
  • 18,169
  • 13
  • 73
  • 107
fatbatman
  • 73
  • 6
  • have you tried `db.type/double`? It seems `double` is preferred https://groups.google.com/d/msg/datomic/MbIIN_rlwng/fEJ0vPh66XAJ – leeor Sep 26 '15 at 07:49
  • Do you want to store 1.0 as 1, or do you want to be able to store 1.5 as well? And do you need to store 1.5 exactly, or is floating precision acceptable? – August Lilleaas Sep 26 '15 at 19:15

1 Answers1

1

You can't store both ints and floats in the same schema attribute in Datomic. So you'll need to coerce the value to whatever type you pick (probably float or double here) appropriately before transacting it. You can do this in the code performing the transaction, or could even do it in a transaction function.

Alex Miller
  • 69,183
  • 25
  • 122
  • 167