Getting Rid of Scientific Notation in SPARQL Output

I’m often writing SPARQL queries to hand off for subsequent processing.  Not everyone wants the default scientific notation (2.5E0, 5.0E-1) that is the default for our floats and doubles.

Two easy ways to get rid of the scientific notation.  One in the output:

select (xsd:decimal(?hrs) AS ?decHrs) {?s rdf:type gist:Duration. ?s gist:decimalValue ?hrs } LIMIT 5

The xsd:decimal in the select part of the statement does the conversion (note you have to alias teh result in this case to ?decHrs)

Or we can do it in the WHERE clause

select ?decHrs {?s rdf:type gist:Duration. ?s gist:decimalValue ?hrs BIND(xsd:decimal(?hrs) AS ?decHrs)  } LIMIT 5

Which might be handy if you wanted to do some math and wanted to get everything to decimal first.

Scroll to top