# Removing Decimal Points? Can it be done using a rule?

Hello everyone,

I can’t seem to find the answer to this question, although it appears to have been covered a few times.

I’m still running with OH02, while I work on migrating to OH03 and learn what has changed. Using the BMWConnected Binding to access data from my wife’s Mini I have found a small problem, namely the fuel range which is calculated in Meters rather than Miles. It’s a simple conversion, but the results return with a decimal place. Manipulating this in the sitemap is easy enough, however I’d like to use the whole number within a number of rules.

Is there a way to remove the decimal point from a variable and update the item? For example if the item below

Car_Mini_Range

is 101540 meters the rule below will output 63.09418767942138. I’m not interesting in rounding up or down, I just want to remove everything after the decimal point and be left with the miles as in 63.

``````Number:Length Car_Mini_Range "Available Fuel Range" { channel="bmwconnecteddrive:CONV:73aee344:VINGOESHERE:range#fuel" }
Number Car_Mini_RangeMiles "Range [%.0f Miles]"
``````
``````rule "Calculate Range - Mini Cooper"
when
Item Car_Mini_Range changed or
System started
then
val Number vRange = Car_Mini_Range.state
var long vMiles = new DecimalType(vRange / 1609)
logInfo(filename, "Cars: Sarah's Mini has {} Miles of range.", vMiles)
Car_Mini_RangeMiles.postUpdate(vMiles)
end
``````

val vRange = Car_Mini_Range.state as Number
var vMiles = (vRange / 1609).intValue

Perfect, topman. Thanks for that, thankfully a very simple fix.

The Item is a Number:Length. You don’t need the rule to change the units from `m` to `mi`. That’s the whole point of using Units of Measurement.

All you need to do is change your label on `Car_Mini_Range` to `"Available Fuel Range [%.0f mi]"`.

If you want to log it out in a rule you can use UoM for that too.

``````rule "Log Range - Mini Cooper"
when
Item Car_Mini_Range changed or
System started
then
logInfo(filename, "Cars: Sarah's Mini has {} miles of range.",
(Car_Mini_Range.state as QuantityType).toUnit("mi").intValue)
end
``````

I think this would work too:

``````logInfo(filename, "Cars: Sarah's Mini has {.0f} miles of range.",
(Car_Mini_Range.state as QuantityType.toUnit("mi"))
``````

By default, assuming you set the measurement system in Regional Settings it should have use imperial units instead of meters. Unfortunately the default units for length is inches so you’d still need to specify miles as the units you want to use.