How to Format Strings as Currency for SuiteCommerce   

in , August 5th, 2024

Following SuiteCommerce best practices, we will use the built-in “Utils” file to convert strings into currency when required. Passing strings as numbers and converting them at the last minute can have positive effects on future code edits where number manipulation needs to happen.

The “Utils” file can be found in the SuiteCommerce source code here: “SC_version_Live > Commons > Utilities > JavaScript > Utils.ts”.

Load the “Utils” File as a Dependency

First, you will need to load the "Utils" file as a dependency in your file, as in this example:

define('MyFile.Entry',
[
	'Utils'
],
function (
	Utils
){});

Use the “formatCurrency” Function

Next, you will need to use the "formatCurrency" function, which is:

Utils.formatCurrency(amount, this.currencySymbol)

The Function Takes Three Arguments

This "formatCurrency" function takes three arguments, as shown here:

function formatCurrency(
    value: string | number,
    symbol?: string,
    noDecimalPosition?: boolean
)
  • Argument 1: REQUIRED: a string or number that can be converted into currency
  • Argument 2: A string representing the desired currency (the default siteSettings value is used if no argument is passed)
  • Argument 3: This is a boolean representing whether you want a decimal present or not.

Author: Sam Gagliardi


Got stuck on a step in this article?

We like to update our blogs and articles to make sure they help resolve any troubleshooting difficulties you are having. Sometimes, there is a related feature to enable or a field to fill out that we miss during the instructions. If this article didn't resolve the issue, please use the chat and let us know so that we can update this article!


Oracle NetSuite Alliance Partner & Commerce Partner

If you have general questions about SuiteCommerce or more specific questions about how our team can support your business as you implement NetSuite or SuiteCommerce, feel free to contact us anytime. Anchor Group is a certified Oracle NetSuite Alliance Partner and Commerce Partner equipped to handle all kinds of NetSuite and SuiteCommerce projects, large or small!

We are a premium SuiteCommerce agency that creates powerful customer portals. Unlike our competitors, we have already solved your problems.

 
 

Want to keep learning?

Our team of NetSuite professionals has written articles on a wide variety of NetSuite topics, from SuiteCommerce tips, to recommended NetSuite solutions, to available support services, and more! 

Your cart