How can I display a decimal as a percent?

Hello,

 

I have a field with a decimal value representing a percentage, actually I saw it as 0.21, but I want to see as a percent like 21.56%

 

How can I did it?

 

Thanks in advance

Like 0

Like

3 comments

Multiply your decimal by 100. (0,2156 * 100 = 21,56)

 

Hi Julius, thanks, but my question is how to format the decimal to a percent I need to display no just 21,56 I need 21,56%. Thanks again

Create a text field like UsrPercentage and make it a calculated field off of the percentage field. Use the following code inside of the desired page schema, but change UsrPlaceholder to your percentage field.

        attributes: {
            "UsrPercentage": {
                dataValueType: Terrasoft.DataValueType.FLOAT,
                dependencies: [
                    {
                        columns: ["UsrPlaceholder"],
                        methodName: "calculatePercentage"
                    }
                ]
            }
        },
        methods: {
            onEntityInitialized: function() {
                this.callParent(arguments);
                this.calculatePercentage();
            },
            calculatePercentage: function() {
                const decimal = this.get("UsrPlaceholder");
 
                const percentage = decimal * 100;
 
                this.set("UsrPercentage", `${percentage}%`)
            }
        },

This code does not handle percentages being converted back to decimal, so preferably this percentage field will be read only. 

Show all comments