Forum Discussion

dMoney's avatar
dMoney
Active Member
18 days ago

Storing Percentags

Whats the best pracctices for storing percentages against a user's profile.

Eg. I have a use case where I want to store the interest rate applied to a customer's loan on their profile.

Is it best practice to store it as a decimal eg. 0.05 or as a percentage 5.0%?

  • Hello dMoney  

    There isn't a one-size-fits-all best practice here—it depends on how you plan to use the data for segmentation or personalization.

    Personally, I would avoid storing the "%" symbol as part of the value. I would use the attribute "interestRate" and store the value as 5.0. This way, I can avoid performing extra calculations when personalizing content or creating segments.

  • rayelkho's avatar
    rayelkho
    Practitioner III

    Adding to the comments above, it comes down to this: 

    Do you need it as an iteger or a string? Storing as an integer will let you use filters like "More than" and "Less than". It also lets you use math in liquid. As a string, you would be able to just display the content and segmentation would be more challenging, you'd need to use regex. 

    Integer: 0.005
    String: 0.5%

  • TedScott's avatar
    TedScott
    Practitioner III

    Could depend, how do you want to use it? I.E. Personalization (insert into message), Use for targeting such as over/under a specific rate?