1

In date extension there is a text field with name CRT and it contains a decimal value 53.8888889998899988

I want to get an output up to two decimal places that is 53.88.

I am trying to use FormatNumber but when I preview it, I am getting the following error

*The specified attribute or custom object field name was not found for this client.
 Function Call: FormatNumber(@CTR1,D2,en-US)
 Attribute or Field Name: D2*

Please see below code:

%%[
    var @lookupValue
    var @countrow
    var @i
    var @rowCount

    set @lookupValue = "1"
    set @countrow = lookupRows("Total Sent Last 7 days Extract","booleanvalue", @lookupValue)
    SET @i = 1
      set @rowCount = row(@countrow,@i)
      set @CTR1 = field(@rowCount,"CRT")
      set @CTR1 = FormatNumber(@CTR1,D2,en-US)   
      ]%%
      <table width="650" border="0" cellspacing="0" cellpadding="0" style="width:100%; max-width:650px; padding:10px; display:block; border:1px dashed red;">
        <tr>
          <td>
            <strong>No of Emails Opened: </strong> %%=field(@rowCount,"TotalEmailOpens")=%%<br>
            <strong>CTR: </strong> %%=v(@CTR1)=%%%<br>


          </td>
        </tr>
      </table>
4
  • you need double quotes around the D2 and en-US and also, I would recommend using `Format(@CTR1, "N2", "en-US") instead. Mar 14, 2018 at 14:34
  • Did you need it to round up/down, or do you want it cut off at a specific decimal place? Mar 14, 2018 at 14:35
  • @Gortonington, thank you for looking into this. N2 works perfectly. I would want to round the decimal. Strangely link (developer.salesforce.com/docs/…) does not ask to use the double quotes. MC should update the documentation. Thanks again.
    – Chandan
    Mar 14, 2018 at 22:42
  • Can you please post this as an answer? Thanks
    – Chandan
    Mar 15, 2018 at 0:57

2 Answers 2

1

You need double quotes around the D2 and en-US inside of your call otherwise it assumes they are calls for variables/fields.

Also, I would recommend using Format(@CTR1, "N2", "en-US") instead - this will allow it to format numbers stored as strings as well as any that are stored as numbers/decimals.

1

I'd try using FixePoint (F2) as the format type within the FormatNumber AMPscript function.

Example:

%%=FormatNumber(53.8888889998899988, "F2", "en-US")=%%

Result: 53.89

3
  • Thank you, Brad, for looking into this issue. FormatNumber(@CTR1,"N2","en-US") is working fine for me.
    – Chandan
    Mar 14, 2018 at 22:45
  • no worries. Could you add your solution to the post and mark as accepted and resolved. thank you Mar 14, 2018 at 23:34
  • How to add the solution?
    – Chandan
    Mar 15, 2018 at 0:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .