Is there a reason you format money? #115
-
|
i get why you format it in the cp but isnt it easier to make have api calls and frontend work with cents because there is a https://builtwithcargo.dev/frontend/modifiers/format_money but anything i get back is already formatted |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
The Money fieldtype converts the cents into a formatted string as part of the augmentation process. It's similar to how the Markdown fieldtype outputs HTML rather than actual Markdown. It makes it easy to display totals without needing to handle the formatting yourself. If you'd prefer to work with cents, you can use The JSON API returns the augmented values so you can't get the raw values there yourself. You'd have to convert it back to pence manually in JS, like this: cart.subtotal.replace('.', '').replace('€', '') |
Beta Was this translation helpful? Give feedback.
The Money fieldtype converts the cents into a formatted string as part of the augmentation process. It's similar to how the Markdown fieldtype outputs HTML rather than actual Markdown.
It makes it easy to display totals without needing to handle the formatting yourself. If you'd prefer to work with cents, you can use
rawmodifier in your templates to get the "un-augmented" value:The JSON API returns the augmented values so you can't get the raw values there yourself. You'd have to convert it back to pence manually in JS, like this: