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
Shiva Ramesh @ xcdhrShiva Ramesh @ xcdhr 

To remove comma on number field

Hi 

In visualforce page, i am displaying the Number(16,2) fields of salary, wages etc. currently its displaying like this 10,000.00

i need it without comma for i am adding these values dynamically and save on gross pay number field. during addition it takes first two digits of before comma, it takes 10,000.00 as 10. Is there any idea to solve this issue.

 

thank you.

Best Answer chosen by Admin (Salesforce Developers) 
sunil_kumarsunil_kumar

Hi Shiva,

 

var cc3= parseFloat((document.getElementById('{!$Component.theForm:EditPayrollPeriodCalc:payrollsection:Bonus:Bonus1}').value).replace (/,/g, ""));

 

this syntax will return values without comma. Below is code which will solve your purpose:

 

var cc3;
  if(document.getElementById('{!$Component.theForm:EditPayrollPeriodCalc:payrollsection:Salary:Salary1}').value!=''){
  cc3=parseFloat((document.getElementById('{!$Component.theForm:EditPayrollPeriodCalc:payrollsection:Salary:Salary1}').value).replace (/,/g, ""));
  }if(document.getElementById('{!$Component.theForm:EditPayrollPeriodCalc:payrollsection:Wages:Wages1}').value!=''){
  cc3+=parseFloat((document.getElementById('{!$Component.theForm:EditPayrollPeriodCalc:payrollsection:Wages:Wages1}').value).replace (/,/g, ""));
  }if(document.getElementById('{!$Component.theForm:EditPayrollPeriodCalc:payrollsection:Additions:Additions1}').value!=''){
  cc3+=parseFloat((document.getElementById('{!$Component.theForm:EditPayrollPeriodCalc:payrollsection:Additions:Additions1}').value).replace (/,/g, ""));
  }if(document.getElementById('{!$Component.theForm:EditPayrollPeriodCalc:payrollsection:Allowance:Allowance1}').value!=''){
  cc3+=parseFloat((document.getElementById('{!$Component.theForm:EditPayrollPeriodCalc:payrollsection:Allowance:Allowance1}').value).replace (/,/g, ""));
  }if(document.getElementById('{!$Component.theForm:EditPayrollPeriodCalc:payrollsection:Benefits:Benefits1}').value!=''){
  cc3+=parseFloat((document.getElementById('{!$Component.theForm:EditPayrollPeriodCalc:payrollsection:Benefits:Benefits1}').value).replace (/,/g, ""));
  }if(document.getElementById('{!$Component.theForm:EditPayrollPeriodCalc:payrollsection:Bonus:Bonus1}').value!=''){
  cc3+=parseFloat((document.getElementById('{!$Component.theForm:EditPayrollPeriodCalc:payrollsection:Bonus:Bonus1}').value).replace (/,/g, ""));
  }

 

assign cc3 variable to your gross pay variable and it will work.

 

Please visit below url for demo.

 

demo for addition of fields using javascript

 

Suggestion: instead of using javasript for adding all values, use <apex:actionsupport> and call controller method to do all this operation and then render the pageblock.

 

Hope this will help you.

[If it solves your problem, please mark it as solution]



All Answers

sunil_kumarsunil_kumar

Hi Shiva,

 

If you just want to remove comma from display then use <apex:inputtext> or <apex:outputtext> on vf page instead of <apex:inputfield> or <apex:outputfield>.

 

Can you please post your code which will give clear idea of your problem?

 

 

Shiva Ramesh @ xcdhrShiva Ramesh @ xcdhr

page:

<apex:pageBlockSection title="Information" columns="2" id="payrollsection" >                         
                                        		   
                                        		<apex:pageBlockSectionItem Id="Name">
                                        		
								                    <apex:outputLabel value="Payroll Period Name"/>  
								                    <apex:inputField value="{!payroll.Name}" Id="NameValue"/>
								                
								                </apex:pageBlockSectionItem>
                                        		
                                        		<apex:pageBlockSectionItem Id="Salary">
                                        		 
								                    <apex:outputLabel value="Salary"/>  
								                    <apex:inputField id="Salary1" value="{!payroll.Salary__c}" onChange="add();"/> 
								                
								                
</apex:pageBlockSectionItem>
								                
								                <apex:pageBlockSectionItem Id="Wages">
                                        		
								                    <apex:outputLabel value="Wages"/>  
								                    <apex:inputField Id="Wages1" value="{!payroll.Wages__c}" onChange="add();"/> 
								                
								                </apex:pageBlockSectionItem>
								                
								                <apex:pageBlockSectionItem Id="Additions">
                                        		
								                    <apex:outputLabel value="Additions"/>  
								                    <apex:inputField Id="Additions1" value="{!payroll.Additions__c}" onChange="add();"/> 
								                
								                </apex:pageBlockSectionItem>
								                
								                <apex:pageBlockSectionItem Id="Allowance">
                                        		
								                    <apex:outputLabel value="Allowance"/>  
								                    <apex:inputField Id="Allowance1" value="{!payroll.Allowance__c}" onChange="add();"/> 
								                
								                </apex:pageBlockSectionItem>
								                
								                <apex:pageBlockSectionItem Id="Benefits">
                                        		
								                    <apex:outputLabel value="Benefits"/>  
								                    <apex:inputField Id="Benefits1" value="{!payroll.Benefits__c}" onChange="add();"/> 
								                
								                </apex:pageBlockSectionItem>
								                
								                <apex:pageBlockSectionItem Id="Bonus">
                                        		
								                    <apex:outputLabel value="Bonus"/>  
								                    <apex:inputField Id="Bonus1" value="{!payroll.Bonus__c}" onChange="add();"/> 
								                
								                </apex:pageBlockSectionItem>
								                
								                <apex:pageBlockSectionItem Id="Commission">
                                        		
								                    <apex:outputLabel value="Commission"/>  
								                    <apex:inputField Id="Commission1" value="{!payroll.Commission__c}" onChange="add();"/> 
								               
								                </apex:pageBlockSectionItem>
								                 
								                <apex:pageBlockSectionItem Id="EmployeeDetail">
                                        		
								                    <apex:outputLabel value="Employee Detail"/>  
								                    <apex:inputField Id="EmployeeDetail1" value="{!payroll.Employee_Detail__c}"/> 
								                
								                </apex:pageBlockSectionItem>
								                
								                <apex:pageBlockSectionItem Id="FixedDeduction">
                                        		
								                    <apex:outputLabel value="Deduction"/>  
								                    <apex:inputField Id="FixedDeduction1" value="{!payroll.Fixed_Deduction__c}" onChange="add();"/> 
								                
								                </apex:pageBlockSectionItem>
								           
								                <apex:pageBlockSectionItem Id="OtherDeductions">
                                        		
								                    <apex:outputLabel value="Other Deductions"/>  
								                    <apex:inputField Id="OtherDeductions1" value="{!payroll.Other_Deductions__c}" onChange="add();"/> 
								                
								                </apex:pageBlockSectionItem>
								                
								                <apex:pageBlockSectionItem Id="Overtime">
                                        		
								                    <apex:outputLabel value="Overtime"/>  
								                    <apex:inputField Id="Overtime1" value="{!payroll.Overtime__c}" onChange="add();"/> 
								                
								                </apex:pageBlockSectionItem>
								                
								                <apex:pageBlockSectionItem Id="Gross">
                                        		
								                    <apex:outputLabel value="Gross Pay"/>  
								                    <apex:inputField Id="Gross1" value="{!payroll.Gross_Pay__c}" onfocus="this.blur()"/> 
								                 
								                </apex:pageBlockSectionItem>
								                
								                <apex:pageBlockSectionItem Id="Notes">
                                        		
								                    <apex:outputLabel value="Notes"/>  
								                    <apex:inputField Id="Notes1" value="{!payroll.Notes__c}"/> 
								                 
								                </apex:pageBlockSectionItem>
								                
</apex:pageBlockSection>
<apex:pageBlockButtons location="Bottom" >
			                              	
					                            <apex:commandButton value="Save" action="{!savepayroll}" rerender="theForm"/>
					                            <apex:commandButton value="Cancel" action="{!cancelpayroll}" rerender="theForm"/>
					                         
					                        </apex:pageBlockButtons>

 Javascript&colon;

<script>
 	
	function add(){
		   document.getElementById("{!$Component.theForm.EditPayrollPeriodCalc.payrollsection.Gross.Gross1}").value = parseFloat(document.getElementById("{!$Component.theForm.EditPayrollPeriodCalc.payrollsection.Salary.Salary1}").value) 
		    + parseFloat(document.getElementById("{!$Component.theForm.EditPayrollPeriodCalc.payrollsection.Wages.Wages1}").value)
		    + parseFloat(document.getElementById("{!$Component.theForm.EditPayrollPeriodCalc.payrollsection.Additions.Additions1}").value)
		    + parseFloat(document.getElementById("{!$Component.theForm.EditPayrollPeriodCalc.payrollsection.Allowance.Allowance1}").value)
		    + parseFloat(document.getElementById("{!$Component.theForm.EditPayrollPeriodCalc.payrollsection.Benefits.Benefits1}").value)
		    + parseFloat(document.getElementById("{!$Component.theForm.EditPayrollPeriodCalc.payrollsection.Bonus.Bonus1}").value)
		    + parseFloat(document.getElementById("{!$Component.theForm.EditPayrollPeriodCalc.payrollsection.Commission.Commission1}").value)
		    + parseFloat(document.getElementById("{!$Component.theForm.EditPayrollPeriodCalc.payrollsection.Overtime.Overtime1}").value)
		    - parseFloat(document.getElementById("{!$Component.theForm.EditPayrollPeriodCalc.payrollsection.FixedDeduction.FixedDeduction1}").value);
		    
		    }
</script>

 

sunil_kumarsunil_kumar

Hi Shiva,

 

var cc3= parseFloat((document.getElementById('{!$Component.theForm:EditPayrollPeriodCalc:payrollsection:Bonus:Bonus1}').value).replace (/,/g, ""));

 

this syntax will return values without comma. Below is code which will solve your purpose:

 

var cc3;
  if(document.getElementById('{!$Component.theForm:EditPayrollPeriodCalc:payrollsection:Salary:Salary1}').value!=''){
  cc3=parseFloat((document.getElementById('{!$Component.theForm:EditPayrollPeriodCalc:payrollsection:Salary:Salary1}').value).replace (/,/g, ""));
  }if(document.getElementById('{!$Component.theForm:EditPayrollPeriodCalc:payrollsection:Wages:Wages1}').value!=''){
  cc3+=parseFloat((document.getElementById('{!$Component.theForm:EditPayrollPeriodCalc:payrollsection:Wages:Wages1}').value).replace (/,/g, ""));
  }if(document.getElementById('{!$Component.theForm:EditPayrollPeriodCalc:payrollsection:Additions:Additions1}').value!=''){
  cc3+=parseFloat((document.getElementById('{!$Component.theForm:EditPayrollPeriodCalc:payrollsection:Additions:Additions1}').value).replace (/,/g, ""));
  }if(document.getElementById('{!$Component.theForm:EditPayrollPeriodCalc:payrollsection:Allowance:Allowance1}').value!=''){
  cc3+=parseFloat((document.getElementById('{!$Component.theForm:EditPayrollPeriodCalc:payrollsection:Allowance:Allowance1}').value).replace (/,/g, ""));
  }if(document.getElementById('{!$Component.theForm:EditPayrollPeriodCalc:payrollsection:Benefits:Benefits1}').value!=''){
  cc3+=parseFloat((document.getElementById('{!$Component.theForm:EditPayrollPeriodCalc:payrollsection:Benefits:Benefits1}').value).replace (/,/g, ""));
  }if(document.getElementById('{!$Component.theForm:EditPayrollPeriodCalc:payrollsection:Bonus:Bonus1}').value!=''){
  cc3+=parseFloat((document.getElementById('{!$Component.theForm:EditPayrollPeriodCalc:payrollsection:Bonus:Bonus1}').value).replace (/,/g, ""));
  }

 

assign cc3 variable to your gross pay variable and it will work.

 

Please visit below url for demo.

 

demo for addition of fields using javascript

 

Suggestion: instead of using javasript for adding all values, use <apex:actionsupport> and call controller method to do all this operation and then render the pageblock.

 

Hope this will help you.

[If it solves your problem, please mark it as solution]



This was selected as the best answer
Shiva Ramesh @ xcdhrShiva Ramesh @ xcdhr

Thank you. Its adding correctly with and without comma

SFAtlantaSFAtlanta

I have the same issue, when I create a custom "Number" field. Instead of a number like 123456 it's giving me 123,456. How do I resolve this one.

Thanks!

tengeltengel
@sunil_kumar are you still active on the boards? I am trying to implement this solution, it is exactly what I need, but I do not know Javascript very well. Would you mind lending your assistance?