SOLVED

Re: truncating zero character after decimal (Velocity)

Go to solution
Mark_Price
Level 7

truncating zero character after decimal (Velocity)

Seeing a strange issue with a Velocity script and am hoping someone can save my sanity.

 I'm looping over a custom object and extracting values to pull into the email. 

There's a currency field in salesforce called Amount__c that seems to just remove trailing 0s after a decimal when Marketo reads the value.

Example of variable being set: 

#set( $regRefundAmount = "${esc.d}${Automated_Fee_Reimbursement__c.Amount__c}" )

Example Test #1
402.76 turns into: 

$402.76  

Velocity Output for custom object values:
{Address_Change_Expiration_Date__c=2019-09-17, Amount__c=402.76}

Example Test #2 
11.40 turns into:

$11.4

Velocity Output for custom object values:
{Address_Change_Expiration_Date__c=2019-09-17, Amount__c=11.4}

Example Test #3: 
60.00 turns into:

$60

Velocity Output for custom object values:
{Address_Change_Expiration_Date__c=2019-09-17, Amount__c=60}

If I go to SalesForce it will show $11.40 and $60.00 opposed to what the velocity output is showing (?)  

Any ideas? 

1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: truncating zero character after decimal (Velocity)

Not too weird really, floats don't have a fixed number of decimal points to display. Once they get stringified (= display-ified) they're going to keep the shortest possible representation. To display as USD currency with 2 decimals, pass the field to

$number.currency()

View solution in original post

3 REPLIES 3
SanfordWhiteman
Level 10 - Community Moderator

Re: truncating zero character after decimal (Velocity)

Not too weird really, floats don't have a fixed number of decimal points to display. Once they get stringified (= display-ified) they're going to keep the shortest possible representation. To display as USD currency with 2 decimals, pass the field to

$number.currency()
Mark_Price
Level 7

Re: truncating zero character after decimal (Velocity)

Yeah, that worked.   

#set( $regRefundAmount = $number.currency($Automated_Fee_Reimbursement__c.Amount__c) )

The output of the object had me a little confused as to what was going on:  {Address_Change_Expiration_Date__c=2019-09-17, Amount__c=11.4}

Makes sense now.  Big thanks! 

SanfordWhiteman
Level 10 - Community Moderator

Re: truncating zero character after decimal (Velocity)

Yeah, a basic object dump is still calling toString() on every property. 

The only way the dump would format as currency (padded to 2 decimal places at all times) would be of the property were not a standard Float/Integer, but rather a subclass that overrode toString().

Also: ritual reminder to never use floats to store money values (too late now!).