-1

How can i make the result of the calculation to display no decimals - for all the results ?

now the number is variable on a slider that gives a number from : 5000 - 100000 and is then divided or multiplied with : X

the problem if X is somthing like : * 0.0001097 the number i is a mile long

i just want the result to be wihtout decimals

i am a real amateur in this field.. have mercy with me hahah


  function do_on_range_change_pages() {

      $('.betrag').text(pages);

  $('.name1').text((pages * 0.001));
  $('.name2').text((pages * 0.03));
  $('.name3').text((pages / 22));

  }

*how can i make the result of this display no decimals ?*

  $('.name3').text((pages / 22 **?????**));

  • 1
    Need more information on what you mean by "without decimals". Do you intend to Round up? Round down? Round off? – Joseph Dec 10 '22 at 17:10
  • Check out this answer: https://stackoverflow.com/questions/7641818/how-can-i-remove-the-decimal-part-from-javascript-number – Rafael Fu Dec 10 '22 at 17:14

1 Answers1

0

In Javascript, you could remove decimals with severals solutions !

The parseInt() function is the slower (!).

let myNumber = 5.0214;
let myOtherNumber = 5.9;

// With Math.floor() method 
let myNymberWithoutDecimals = Math.floor(myNumber) // 5
let myOtherWithoutDecimals = Math.floor(myOtherNumber)  // 5

// With Math.round() method
let myNymberWithoutDecimals = Math.round(myNumber) // 5
let myOtherWithoutDecimals = Math.round(myOtherNumber)  // 6

// with parseInt()
let myNymberWithoutDecimals = parseInt(myNumber) // 5
let myOtherWithoutDecimals = parseInt(myOtherNumber)  // 5

// with toFixed(number)
myNumber.toFixed(2) // 5.02
myNumber.toFixed(1) // 5.0
myNumber.toFixed() // 5


With your example :

 function do_on_range_change_pages() {

      $('.betrag').text(pages);

  $('.name1').text((pages * 0.001).toFixed());
  $('.name2').text((pages * 0.03).toFixed());
  $('.name3').text((pages / 22).toFixed());

  }

Better advice : new to JS ? Try to use google.

My research : https://www.jsdiaries.com/how-to-remove-decimal-places-in-javascript/

Try https://beta.sayhello.so/, this search engine could find snippets :) !

Have a nice day :)