Currency format : how to do it

Hello,
My issue seems to be easy to resolve but … I don’t find the solution.
In simple words : how can I transform a number in currency format with Robotframework ?

Example : 160000 becomes 160 000 €.

Is there a library or keyword which can do this or must I write a piece of Python code ?

Thanks for your help !

not aware of any robot specific libraries that would to this … but python’s standard library has locale library. However, it will default to use your local “locale” settings (typically via environment variables) and and the output can change from machine to another if they are not set up to be identical locale wise.

Easiest way would probably be to make your own.

Hi John

Does this work for you?

*** test cases ***

currency test
	${number} = 		Set Variable	160000
	${currstring} = 	Evaluate		"{:,.0f} €".format(${number}).replace(',', ' ')
	Should Be Equal As Strings		${currstring}		160 000 €

The builtin Evaluate is pretty useful :+1:t3:

Dave.

1 Like

Hi Dave,

Thanks for your answer.
It seems to be the good way to resolve my issue. I will test it !
Unfortunatly, I’m not a developer and the builtin “Evaluate” is very difficult to understand for me.
If your solution works, I would never found it alone :slight_smile: lol

I come back very fast !

Thanks

Good news !
The Dave’s solution is working !

Thanks a lot :slight_smile:
I’m going to try to understand the code now !

Hi John,

Both format and replace are standard python string functions

I used the string number formatter to format the number with commas( , ) and then used replace to replace the commas with spaces.

Learning python is not required for using robot framework, but learning some of the basics is pretty useful, I linked to the W3Schools site rather than the python documentation as I feel that W3Schools explains things better for non programmers, they also have a good python tutorial

Good luck with the learning,

Dave.

Thank you! This worked beautifully!

1 Like