I'm creating a lightning component with a lightning:input
, but I have an issue with decimal places and currency formatter
.
This is my code:
<lightning:input name="foo" value="foo" type="number" formatter="currency" step="0.01"/>
Without decimal places is saved correctly:
Input: 3
Saved value: 3.00
But with decimal places it saves a wrong value:
Input: 0.03
Saved value: 3.00
Another example:
Input: 4.32
Saved value: 432.00
What i'm doing wrong?
Thanks
EDIT
SOLVED! I wasn't serializing the list to JSON. Sending as JSON to the apex controller and deserializing in the apex controller solved the issue :).
UPDATE 2
I faced this issue again with a LWC datatable, and the solution is the same. Here is the code for anyone who needs it:
LWC
saveAccounts({listAccounts:JSON.stringify(this.draftValues)})
.then(...
Apex Controller
public static void saveAccounts(String listAccounts){
try{
update (List<Account>)JSON.deserialize(listAccounts, List<Account>.class);
...
}
Best Answer
You can try this :
<lightning:input name="foo" value="foo" type="currency" step="0.01"/>