Build an open future with us.

Invest in Mycroft and become a community partner.

Adapt and decimal numbers


#1

I’m trying to use a regex to get a number that can be represented as X or X.XX (so a whole number or a number with 2 decimal points)

It appears though, that my regex is not returning the number correctly. Any thoughts here?

Command passing to Adapt
Set DecimalValue to 14.4

Then I have the regex entity parser
engine.register_regex_entity("(?P<DecimalValue>([-+]?[0-9]*\.?[0-9]+))")

So in this scenario, Adapt is returning 14

If I change the command to
Set DecimalValue to .4

Then adapt returns .4

The problem is it won’t return 14.4

Any thoughts?

By the way…Adapt is AMAZING


#2

I round using:

from decimal import Decimal confidence = float(("%.2f" % round(confidence,2)))

I’ll be honest I’m a newb so I kind of copy/pasted that from I believe a stack overflow or something. Seems to work well. The Stack Overflow I had found said there was some reason to import decimal vs using the native rounding function linked to below.

https://docs.python.org/2/library/functions.html#round