function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
pradyprady 

How to display a decimal value default to 2 zero after decimal point

I have textbox which has a decimal  value fetched from controller. I need to show the value with 2 zero's after decimal point. Currently its displaying just 1 zero.

 

 

<apex:inputText styleclass="tb2" value="{!a.TimeCardObj.Monday_Hours__c}"/>

 

 

Thanks

Prady

Bhawani SharmaBhawani Sharma

Youi can solve this by adding a zero manually :

<apex:inputText styleclass="tb2" value="{!a.TimeCardObj.Monday_Hours__c}0"/>
pradyprady

If the returned value from controller is 7.25 then would it not display 7.250? I just want to show 2 places in decimal.

Bhawani SharmaBhawani Sharma

You ca use javascript to format this field.

var val = document.getElementById('inputTextId').value;

val = val.substring(from . to val.length);

and then

if(val.length < 2)

document.getElementById('inputTextId').value = document.getElementById('inputTextId').value + '0';

kxa422kxa422

I've never try with an inputfield, but with output, there is a formatting functionnality.

 

<apex:outputText value="{0, Number, #0.00}"><apex:param value="{!a.TimeCardObj.Monday_Hours__c}" /></apex:outputText>

Bhawani SharmaBhawani Sharma

Hey Thanks , I was not aware with such kind of functionality.

I tried this with the input field , but doesn't support.

 

rosscorossco

Hi Guys

 

Any further progress on this?

 

Regards

Ross

Bhawani SharmaBhawani Sharma

Hey,

 

 

<apex:pageBlockSectionItem>
    Monday Hours
    <apex:outputText value="{0, Number, #0.00}">
        <apex:param value="{!a.TimeCardObj.Monday_Hours__c}" />
</apex:outputText> </apex:pageBlockSectionItem>

 It works perfectly.

 

 

rosscorossco

Sorry I'm looking for way to format the text on a INPUT (not an OUTPUT)

 

Thanks

Ross

 

Carole Reynolds1Carole Reynolds1

great solution for me, exactly what I needed - thx!

Ernest NyarkoErnest Nyarko
<apex:outputText value="{0,number,$#,###,###.00}"><apex:param value="{!variable.attribute}"/></apex:outputText>