Skip to main content
Inspiring
February 20, 2024
Answered

Remove values after the period

  • February 20, 2024
  • 2 replies
  • 746 views

Continue my project
I ran into this problem
I would like to delete the values after the dot,
Is there something to do this?

rightly the code will be adapted to uxp.

 

This topic has been closed for replies.
Correct answer Stephen Marsh

OK, it would depend on the goal, one way is to parse the floating number as an integer:

 

var theValue = 52.51282051;
var theNewValue = parseInt(theValue);
alert(theValue + "\n" + theNewValue);

 

https://www.w3schools.com/jsref/jsref_parseint.asp

 

But you could have other goals, such as rounding up or down to the nearest integer?

 

EDIT:

 

The Math.abs() Method
The Math.ceil() Method
The Math.floor() Method
The Math.round() Method
The Math.fround() Method
The Math.trunc() Method

2 replies

Stephen Marsh
Community Expert
Stephen MarshCommunity ExpertCorrect answer
Community Expert
February 20, 2024

OK, it would depend on the goal, one way is to parse the floating number as an integer:

 

var theValue = 52.51282051;
var theNewValue = parseInt(theValue);
alert(theValue + "\n" + theNewValue);

 

https://www.w3schools.com/jsref/jsref_parseint.asp

 

But you could have other goals, such as rounding up or down to the nearest integer?

 

EDIT:

 

The Math.abs() Method
The Math.ceil() Method
The Math.floor() Method
The Math.round() Method
The Math.fround() Method
The Math.trunc() Method

Inspiring
February 20, 2024

Stefano works wonderfully
I managed to adapt it to uxp successfully.

thank you you are a great friend.

 

Stephen Marsh
Community Expert
Community Expert
February 20, 2024

You're welcome. Sorry, it takes me longer to think in UXP:

 

let theValue = 52.51282051;
let theNewValue = parseInt(theValue);
require('photoshop').core.showAlert(theValue + "\n" + theNewValue);

 

Stephen Marsh
Community Expert
Community Expert
February 20, 2024

Do you mean to remove a filename extension such as from myFile.jpg to myFile – or do you mean something else?

 

Can you please provide a clear before and after example? Some code snippet? Something? Anything?  :]

 

Inspiring
February 20, 2024

no it is not a jpg extension
and the value you see on the slider.

 

Stephen Marsh
Community Expert
Community Expert
February 20, 2024

I can't see anything?

 

If you're replying via email, the web interface has to be used to insert images.