Forum Discussion

Henrik's avatar
Henrik
Advisor
11 years ago

Endpoints and numbers

Hi,

I have an important issue with endpoints and numbers. All numbers above 1000 are transformed in 1 000 with a space between "1" and "000". So when I want to make simple rest calls with a number (user.id for instance), it fails when it's higher than 999.


Example: I want the last messages written by the user whose id is 6207.

"/users/id/${user.id}/posts/latest" or "/users/id/" + user.id + "/posts/latest"

will give

"/users/id/6 207/posts/latest" instead of "/users/id/6207/posts/latest"

I've also tested it with the freemarker '?number' function. It also fails to give 1000 without space.

 

Meanwhile, I've discovered this article: 
https://lithosphere.lithium.com/t5/developers-discussion/user-id-number-format-issue/m-p/112673#M4135 

Which was close to my issue. So I tried user.id?c and it worked well! 

But everything is a bit messy in my head. 
For instance, if I want to transform a string to a number, should I use "?number?c" or just "?c" ? 
Why ?number and int don't behave the same way in endpoints than in custom components? 

Thanks for your help! 
Henrik

  • PaoloT's avatar
    PaoloT
    Lithium Alumni (Retired)

    Hi Henrik 

     

    when it comes to numbering, dates etc ... all becomes very relative to the specific locale you are considering. So for example in some countries a certain number could be written in a specific format with a different decimal or thousdands separator etc ... 

     

    If you intend to use a number programmatically - then it's recommended to use the ?c built in to indicate Freemarker that the value is not meant to be "human readable" ( see documentation - where it's explained in better words than mine! )

     

    Does this make sense?

     

     

     

     

    • ChiaraS's avatar
      ChiaraS
      Lithium Alumni (Retired)

      DougS are endpoints handling freemarker objects in a different way? I agree with Paolo that we should use "?c" to be on the safe side, but it's still weird to me that ${user.id} returns a different value inside an endpoint compared to a custom component (I checked on another instance and I get "330,940" from the endpoint and "330940" in the component)...

      • nathan's avatar
        nathan
        Executive

        It is a bit odd. I assume it's picking up a different localisation rules for some reason.

         

        Thinking about it, custom components always reside within the community user interface, so you'd expect them to inherit the community's localisation settings (including number format). End points on the other hand are designed more for APIs, and therefore are more location agnostic by design.