1

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 :).

  • Is there a logic in between as how are you collecting the value from the input component and then saving it? With what you have as input, your saved value should match. Also, what is the field type where you are saving the values? – Jayant Das Nov 13 '18 at 19:28
  • Any logic, just saving the field as recived. The field type is currency (16,2). Having the same problem with other fields with percentages (8,2). – Wyrncael Nov 13 '18 at 20:30
  • 1
    I verified with a quick test and it works as expected. The values as passed from the component is saved exactly the way it should be. You should verify if there's any other logic viz., trigger, workflow rule, etc. on that field which is causing this issue. There's no problem in the component itself. – Jayant Das Nov 13 '18 at 20:58
  • Testing I've seen that the helper sends 3.2 and the apex controller is receiving 32 (Sending and receiving a List<CustomObject__c). Is in that point were the value changes :S. – Wyrncael Nov 14 '18 at 8:42
  • 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 :). – Wyrncael Nov 14 '18 at 11:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.