diff --git "a/class-wb\\DataValueQuantity.php" "b/class-wb\\DataValueQuantity.php" index e5c3d14..af0a3fe 100644 --- "a/class-wb\\DataValueQuantity.php" +++ "b/class-wb\\DataValueQuantity.php" @@ -1,65 +1,63 @@ . # Wikibase namespace wb; /** * A DataValue for a quantity. */ class DataValueQuantity extends DataValue { /** * @param $value mixed amount Any number e.g. 0 * @param $wikidata_unit_id string Wikidata ID of a unit e.g. 'Q11573' for metre * @param $upper_bound mixed The $value at its maximum error e.g. +1 * @param $lower_bound mixed The $value at its minimum error e.g. -1 */ public function __construct( $amount, $wikidata_unit_id, $upper_bound = null, $lower_bound = null ) { $value = [ - 'amount' => self::int2string( $amount ), + 'amount' => self::sign( $amount ), 'unit' => "http://www.wikidata.org/entity/$wikidata_unit_id" ]; if( null !== $upper_bound ) { $value['upperBound'] = self::int2string( $upper_bound ); } if( null !== $lower_bound ) { $value['lowerBound'] = self::int2string( $lower_bound ); } parent::__construct( DataType::QUANTITY, $value ); } /** * Convert a number to a prefixed string e.g. 1 is converted to '+1' * * @param $n mixed * @return string */ - private static function int2string( $n ) { + private static function sign( $n ) { return $n > 0 ? '+' . $n : '-' . $n; } /** * @return string */ public function __toString() { $value = $this->getValue(); - return sprintf( '%f', - $value['amount'] - ); + return $value[ 'amount' ]; } }