Float rounding issue

Using some SPARQL conversion I identified a possible issue with float rounding.

consider the following SPARQL commands

insert data { <#1> <#p1> 144769387.5 }

and then

insert { <#2> <#p2> ?o }
where {
   <#1> <#p1> ?o_raw .
   BIND( STRDT( STR( ?o_raw), xsd:float) AS ?o)
}

running

select * where {?s ?p ?o}

I get back

<tag:stardog:api:#1> <tag:stardog:api:#p1> 144769387.5
<tag:stardog:api:#2> <tag:stardog:api:#p2> "1.44769392E8"^^<http://www.w3.org/2001/XMLSchema#float>|

notice that there is a difference in the numbers: 144769387.5 vs 144769392

compared to the number size the difference is quite small 4.5/144769387.5 but caused us some trouble.

Is this behavior expected? and if yes what would be the best way to keep the exact original values in place?

Thank you in advance

Floats are inherently imprecise because of the way they’re represented. Try using xsd:decimal