Jump to content
  • 0

Limit calculated field decimal places in footer of datapage


DesiLogi

Question

Hello,

I've been trying to find a solution to this for awhile. Does anyone know how to limit/round the decimal places on a field and calculated field, over-riding whatever the setting is in the Localization. I need to do this because in some places I need the localization to show 3 decimal points for percentages and sometimes 0 decimal places (rounding whatever the value is).

This is because I have multiple fields on the same datapage that use percentages for display and one needs 3 decimal places and the other needs 0. It makes it sloppy looking to always have .000 after the values for the field and/or calculated field that should normally so none. Thanks for any help. 

Link to comment
Share on other sites

7 answers to this question

Recommended Posts

  • 0

Hi Vitalikssss,

Thanks for the tip- I know how to do that for a normal field. The question is for a field in an html tag (actually the footer but same thing basically) where you use [@calcfield:1%] to pull the result. That's where I need to make the percentage round to 0 decimal points. 

Link to comment
Share on other sites

  • 0

Hi @DesiLogi, I'm not sure of what DataPage you are using and if this is your expected results but here's what I've done using Details page and custom coding.

Since I was not able to get reference the calculated field ID in JavaScript, I added a Virtual Field then receive the value of calculated field.

image.png.6a4ad98bff02e5c39a35870e9b129d94.png

Then, I created a span id for the footer that will serves as the placeholder of the percentage value later. I also created a function that will determine if the calculated field value has a decimal using the modulo operator, and if so, it will remove the decimal using the parseInt() function and multiply by 100 to get the percentage value.

<p style="color: red;"><span id="footer" style="color: red;"></span> %</p>

<script>

document.addEventListener('DataPageReady', function (event) {

var calc = document.getElementById("cbParamVirtual1").value;
var modu = calc % 1;

    if (modu != 0) {
       document.getElementById("footer").innerText = parseInt(calc)*100;
}
    });
</script>

I just added a percent (%) symbol inside the <p> tag and added a font color.

image.png.90e202aae870f1f899e13f1f3681db42.png

Link to comment
Share on other sites

  • 0

Hi - Just to add on this post. If you would like to format the number field to two decimal places - For example, on whole numbers such as 16, it would be 16.00.

You can use this formula

STR([@field:Number], 6, 2)

The STR() function returns a number as a string.

Result:
16 = 16.00
15.345878 = 15.35

References:
- https://howto.caspio.com/function-reference/#:~:text=Str(number%2C length %2C precision)
- https://www.w3schools.com/sql/func_sqlserver_str.asp

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...