Skip to content

microbit.scale() to return a float if the arguments for the to parameter are floats. #770

Closed
@microbit-carlos

Description

@microbit-carlos

This is to mirror the change in V2:

If any of the values inside the tuple for the to paramenter are floats, then microbit.scale() will return a float, otherwise it will return an integer.

For example:

# This Celsius to Fahrenheit conversion will return a float
this_will_return_float = scale(value, from=(0, 100), to=(32.0, 212.0))

# This conversion between the accelerometer output to a 1 byte range will return an integer
this_will_return_int = scale(accelerometer.get_x(), from_=(-2000, 2000), to=(0, 255))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions