N
N
Nick Krogan2016-10-22 09:07:25
Sass
Nick Krogan, 2016-10-22 09:07:25

How to round the result of a function?

Good day to all. there are two functions written in scss:

// First function
$pxbase:16;
@function emy($pxsize:$pxbase) {
    @return ($pxsize/$pxbase)+em;
}

// Second function
$base:1024;
@function perc($pxl:$base) {
    @return ($pxl/$base*100)+%;
}

// Task
p {
  font-size: emy(23);
  width: perc(573);
}

//Result
p {
 font-size: 1.4375em; 
width: 55.95703%; 
}

the first converts pixels to em, the second converts pixels to percentages.
What else needs to be written, and is it possible for the final values ​​to be rounded down? This is especially true when converting pixels to percentages.
And yet - how to determine the sizes of blocks and text, if there is a layout of only one specific resolution? Approximately? I'm a beginner, don't throw stones too hard :)
UPD: rounding not to a whole number, but to hundredths

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Ketov, 2016-10-22
@nollac

The ceil() and floor() functions are described here . Usage examples can be seen by clicking on a function in the list.

A
Anton Bobylev, 2016-10-22
@dpigo

Multiply by 100, round up, divide by 100. You will get rounding to hundredths.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question