B
B
Brain Storm2014-02-23 15:17:04
JavaScript
Brain Storm, 2014-02-23 15:17:04

rounding values ​​in javascript

I need a script that allows rounding values.
For example:
23 in 25
52 in 50
110 in 100.
The main thing is that the number is a multiple of 25.
Maybe someone knows how? or do you have any work?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey, 2014-02-23
@EkLast

function round(n) {
  var func = n % 25 < 25/2 ? 
      Math.floor : Math.ceil;
  return func(n/25)*25;
}

you can think of many options. You can subtract the remainder from the division and sort it out there already ... The task is really elementary.

V
Vampiro, 2014-02-23
@Vampiro

Call your 5th-6th grade math teacher. She will be pleased, and you will fill in the gaps in the division operations with remainders!)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question