0

The code is for an audio system when the user presses Up arrow or Down arrow then the volume changing with 0.05 up or down (5%) on the audio volume. That code isn't important. I just said because the changing value is 0.05 that means when I want to display the current volume the numbers sometimes look like this:
A good one:
A bad one:

Anything I could use? Maybe RegEx? (but how) Here is the code:

Element.innerHTML = "Hangerő: <strong>" + (audio_element.volume * 100) + "%</strong>"
hoaaiww
  • 15
  • 4

1 Answers1

0

Try parseInt() .

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt

Element.innerHTML = "Hangerő: <strong>" + parseInt(audio_element.volume * 100) + "%</strong>"
script0
  • 387
  • 2
  • 12
  • Thanks! It works! but the numers still in ex.: 49 not 50 – hoaaiww Dec 12 '21 at 19:54
  • Ok. Use [Math.round()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/round) instead of parseInt() – script0 Dec 12 '21 at 20:37