float Literal precision lost when serializing graph to turtle or n3 · Issue #237 · RDFLib/rdflib (original) (raw)

When I serialize a conjunctive graph to turtle or N3 I lose the 1/100th decimal place in my double literal. Bug or user-error? Thanks, JH

from rdflib import URIRef, Literal, Namespace
f1 = 1.91
type(f1)
<type 'float'>
l1 = Literal(f1)
l1
rdflib.term.Literal(u'1.91', datatype=rdflib.term.URIRef(u'http://www.w3.org/2001/XMLSchema#double'))
from rdflib.graph import ConjunctiveGraph
g = ConjunctiveGraph()
sub = URIRef('http://ex.com/blah')
pred = URIRef('http://ex.com/pred')
g.add( (sub, pred, l1))
g.serialize(format='turtle')
'@Prefix ns1: http://ex.com/ .\n\nns1:blah ns1:pred 1.9e+00 .\n\n'

where's is the 0.01?!

g.serialize(format='n3')
'@Prefix ns1: http://ex.com/ .\n\nns1:blah ns1:pred 1.9e+00 .\n\n'

still missing

g.serialize(format='xml')
'\n<rdf:RDF\n xmlns:ns1="http://ex.com/"\n xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"\n>\n <rdf:Description rdf:about="http://ex.com/blah">\n <ns1:pred rdf:datatype="http://www.w3.org/2001/XMLSchema#double">1.91/ns1:pred\n /rdf:Description\n/rdf:RDF\n'

xml looks correct...