Client SDK (REST / Android / Objective-C / Swift / JS )
Codeless
Application ID
5B75038B-CF13-4B09-AB38-4BCF5E7002BC
hello team backendless,
iam use dopsource
how to convert double to currency format? Thanks
Codeless
5B75038B-CF13-4B09-AB38-4BCF5E7002BC
hello team backendless,
iam use dopsource
how to convert double to currency format? Thanks
Hello @xiaomieya
please provide example values, what you’ve got and what you want to get at the end
Regards, Vlad
hello @vladimir-upirov thanks for your respone.
I have a data table with double data types. like this.
when api call on dropsource the result is 2000.0 I want to get is 2,000 .
Thanks @vladimir-upirov
When you put comma to separate digits in a number, it technically becomes a string. So while 2000
is an Double, "2,000"
is already a string. To do this, you’d need to write logic either in codeless or on the Dropsource side to format the value that way.
hello @mark-piller
can you give me an example of how to convert double to string using codeless? thanks
Hi Xia,
Unfortunately, I cannot, this would be something our professional services team can do. This would be rather straight-forward - convert the number to a string and put a comma every 3 characters.
Mark
try to create a Codeless Custom Function:
and as result you will have the following:
0 => "$ 0"
2000 => "$ 2,000"
12330 => "$ 12,330"
89033 => "$ 89,033"
780 => "$ 780"
78 => "$ 78"
123456789 => "$ 123,456,789"
Regards, Vlad
oops, just noticed, there is a bug, the first char comes twice and there is no the last char in the result, let me fix
I’ve updated screen with logic and results
Hi @vladimir-upirov, since this post is kind of old. Is this function above still the fastest way to format an INT into currency today? Please advise.
Thank you.
Hi @vladimir-upirov , hope you are well. Did you get the chance to look at my previous question above? Thanks
Hello @KLoic
Sorry for the delay
I’m not sure about the speed but using RegExp it definitely looks simpler
(\d)(?=(\d{3})+(?!\d))
You can try it out at the following link https://backendlessappcontent.com/7E25B48A-05FA-0B5D-FFAE-63CC0AC26C00/E9920D04-8F81-D6EC-FFBB-4D4D78486100/files/ui-builder/containers/currency/index.html?page=landing
Regards, Vlad
Hi @vladimir-upirov ,
Can you show me a RegExp codeless block for changing a string from 1000 to € 1.000,00?
@KLoic @Michel_Loriaux
Maybe there is even an easier way to solve this, but here is my solution with a Javascript Snippet in a Custom Function.
And here is the Javascript in the Custom Code:
It is just covering one currency format, but it should be easy to add other formats as well.
Please let me know if there is an easier way. I found the RegEx solution to complicated in a multi-currency environment.