+ Start a Discussion
Andreas Rikstad 5Andreas Rikstad 5 

Problem with currency in Lightning component

Hi all. I v\have a problem with my component.
I'm using lightning datatable with enabled in line editing to edit prices for products. Datatable definition looks like this:
<lightning:datatable
keyField="Id"
aura:id="table"
data="{!v.discountCodeItems}"
columns="{!v.columns}"
hideCheckboxColumn="true"
defaultSortDirection="asc"
draftValues="{!v.draftValues}"
oncellchange="{!c.handleCellChange}"
showRowNumberColumn="false"
isLoading="{!v.isLoading}"
wrapTextMaxLines="10"
onsave="{!c.handleSave}"/>
Columns definition:
component.set("v.columns",[
            {label : 'Product Name', fieldName : 'linkName', type : 'url',typeAttributes : {label : {fieldName : 'Name'}}},
            {label : 'Sales Price', fieldName : 'Sales_Price__c', type : 'currency', typeAttributes: { currencyCode: 'NOK'}, editable: true},
            {label : 'List Price', fieldName : 'List_Price__c',type : 'currency'},
            {label : 'Discount', fieldName : 'Discount', type : 'text'}
        ]);
I read changed value using:
var draftValues = event.getParam('draftValues');
and send it from component to Apex.
Te problem is when I change price from 24.00 to 24.89 JS controller sends:
[{"Sales_Price__c":"24.89","Id":"a699E000000Mc0JQAS"}]
but Apex receives
{Id=a699E000000Mc0JQAS, Sales_Price__c=2489.00}
If I change price back to 24 (without decimal part), Apex receives 24.
Do you know why it happens?
Best Answer chosen by Andreas Rikstad 5
Janet EpebinuJanet Epebinu

Hi Andreas ,

Use Decimal instead of Currency. 
Check what is written under Decimal data type in the Documentations in this link
 https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/ref_attr_types_basic.htm

Thanks

All Answers

AnudeepAnudeep (Salesforce Developers) 
Hi Andreas - Can you try using type as Number instead of Currency

https://developer.salesforce.com/docs/component-library/bundle/lightning:datatable/documentation
Andreas Rikstad 5Andreas Rikstad 5
Hi. I tried to use number and it does not help.
Janet EpebinuJanet Epebinu

Hi Andreas ,

Use Decimal instead of Currency. 
Check what is written under Decimal data type in the Documentations in this link
 https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/ref_attr_types_basic.htm

Thanks

This was selected as the best answer
Andreas Rikstad 5Andreas Rikstad 5
Thank you Janet.
I changed the field to Decimal and it works.Anyway I have to do small investigation why is like that because in documentation they use currency as a field type in column definition:
https://developer.salesforce.com/docs/component-library/bundle/lightning:datatable/documentation