Mark
Mark

Reputation: 3859

Is there a way to set a max limit to math operations in dart?

I have the following math operation:

    var _baseFontSize = _userfontsize*8;
    if (_baseFontSize > 14) { _baseFontSize = 14.0; }

Essentially whatever the _userfontsize is, my _baseFontSize should be 8x that number, but never exceeding 14.0.

Instead of doing this math operation in 2 lines as might be conventional, is there a way to set a max limit to this (or any given) math operation in dart?

Upvotes: 0

Views: 92

Answers (1)

julemand101
julemand101

Reputation: 31299

You can import dart:math and do something like this with min:

var _baseFontSize = min(_userfontsize * 8, 14.0);

T min<T extends num>(T a, T b)

Returns the lesser of two numbers.

Upvotes: 1

Related Questions