cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Post Prodigy
Post Prodigy

Convert string to currency

I found a couple posts on this but nothing that is working for me.

 

I have a variable of a number like 348749879

 

I use a compose of:

concat('$',div(variables('Revenue'),100),'.',if(less(mod(variables('Revenue'),100),10),concat('0',mod(variables('Revenue'),100)),mod(variables('Revenue'),100)))

 

but this returns: $3487498.79.79

 

I think the formula I am trying assumes there is a cents listed.

 

In my case the number could be 1234 or 1234.56 or 1234.5

 

I would like them to show as: $1,234.00 or $1,234.56 or $1,234.50

 

Does anyone have a formula that accomplishes this already?

 

Thanks,

Terry

2 ACCEPTED SOLUTIONS

Accepted Solutions
Highlighted
Community Support
Community Support

Re: Convert string to currency

Hi @Mattw112IG ,

 

You can create an Excel file online in SharePoint, like this:

Annotation 2019-07-19 182900.png

Then create a flow to update the excel file using the function DOLLAR:

=DOLLAR(Number,2)

After that, create get a row to get the converted number.

 

Annotation 2019-07-19 181557.png

This is a screenshot of the successful result:

Annotation 2019-07-19 181743.png

Please have a try, I hope it can help you.

 

Best Regards,

Community Support Team _ Barry
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Highlighted
Advocate V
Advocate V

Re: Convert string to currency

Challenge accepted!

 

I expanded my absurd expression to include values under 1 trillion and posted it to Format number with thousands separator in Flow email, where I originally put my solution.

View solution in original post

15 REPLIES 15
Highlighted
Dual Super User III
Dual Super User III

Re: Convert string to currency

@Mattw112IG 

You declared variables('Revenue') as float, right?

Your expression is valid for int variables

 

Flow_int_float.png

Hope this helps



Each time you click on any of our inspiring answers 'Thumb up' icon...
...an ewok scapes from the stormtroopers.

Be grateful, Thumbs up! Save the Galaxy for free!


Escribo sobre Power Automate en:
https://medium.com/anyone-can-automate/

Proud to be a Flownaut!



Highlighted
Post Prodigy
Post Prodigy

Re: Convert string to currency

Thanks,

Even in your tests though it looks like it takes the last two digits and makes them cents instead of dollars??

 

I just added a compose to mine: int(<the revenue number>)

 

But the formula turned 40000 into $400.00

 

The last two digits should not be turned into cents??

 

Thanks,

Terry

Highlighted
Dual Super User III
Dual Super User III

Re: Convert string to currency

Terry

Not sure I understood you. I mean, in your expression you are dividing the content of variable Revenue by 100. That's the reason why it takes the last two digits and makes them cents instead of dollar

Hope this helps



Each time you click on any of our inspiring answers 'Thumb up' icon...
...an ewok scapes from the stormtroopers.

Be grateful, Thumbs up! Save the Galaxy for free!


Escribo sobre Power Automate en:
https://medium.com/anyone-can-automate/

Proud to be a Flownaut!



Highlighted
Post Prodigy
Post Prodigy

Re: Convert string to currency

Right, I don't want that and need a formula that handles all the situations I mentioned (no cents, cents, one digit of cents).  Was hoping someone already had one.

 

Thanks,

Terry

Highlighted
Dual Super User III
Dual Super User III

Re: Convert string to currency

Hi again

Have you tried to convert whatever 'number as string' you receive to float? I mean before adding the $ sign.

Hope this helps



Each time you click on any of our inspiring answers 'Thumb up' icon...
...an ewok scapes from the stormtroopers.

Be grateful, Thumbs up! Save the Galaxy for free!


Escribo sobre Power Automate en:
https://medium.com/anyone-can-automate/

Proud to be a Flownaut!



Highlighted
Dual Super User III
Dual Super User III

Re: Convert string to currency

@Mattw112IG 

 

I have created an array for testing purposes, 3 string items with the 3 different formats you mentioned before

Once the array is initialized, I apply the following expression

createArray(concat('$',float(variables('ArrayOfNumbersAsStrings')[0])),concat('$',float(variables('ArrayOfNumbersAsStrings')[1])),concat('$',float(variables('ArrayOfNumbersAsStrings')[2])))

flow_float.png

Hope this helps

 



Each time you click on any of our inspiring answers 'Thumb up' icon...
...an ewok scapes from the stormtroopers.

Be grateful, Thumbs up! Save the Galaxy for free!


Escribo sobre Power Automate en:
https://medium.com/anyone-can-automate/

Proud to be a Flownaut!



Highlighted
Dual Super User III
Dual Super User III

Re: Convert string to currency

Hi again

 

If you need also the comma, in the following post tyou will find an expression to format a float less than 1 million into a string for currency (not including the dollar symbol) with a thousands separator and 2 digits after the decimal. I haven't tested myself, but it received 4 kudos, so I guess several people find it extremely useful

https://powerusers.microsoft.com/t5/Using-Flows/Format-number-with-thousands-separator-in-Flow-email...

 

Happy Flowing!



Each time you click on any of our inspiring answers 'Thumb up' icon...
...an ewok scapes from the stormtroopers.

Be grateful, Thumbs up! Save the Galaxy for free!


Escribo sobre Power Automate en:
https://medium.com/anyone-can-automate/

Proud to be a Flownaut!



Highlighted
Post Prodigy
Post Prodigy

Re: Convert string to currency

@efialttes,

Thanks.  I followed the link to your other post and used that code and it works great up to $999,999.99...

 

I've tried disecting the formula and my eyes are getting cross eyed 😉

 

How do I make this handle up to $999,999,999.99

 

I would think I would just need to add one more section like the one below after the last one?  But how would it know where to start?

 

    concat(
      substring(
        string(variables('myFloat')),
        0,
        max(0, sub(length(first(split(string(variables('myFloat')), '.'))), 3))
      ),
      ',',
      substring(
        first(split(string(variables('myFloat')), '.')),
        max(0, sub(length(first(split(string(variables('myFloat')), '.'))), 3)),
        min(3, length(first(split(string(variables('myFloat')), '.'))))
      )
    ),

 

or is it simplier than that and just need to change the 3's to 6's? or something?

 

Thanks,

Terry

Highlighted
Dual Super User III
Dual Super User III

Re: Convert string to currency

@Mattw112IG 

I guess @degvalentine is the right contact person for your question

Hope this helps

 



Each time you click on any of our inspiring answers 'Thumb up' icon...
...an ewok scapes from the stormtroopers.

Be grateful, Thumbs up! Save the Galaxy for free!


Escribo sobre Power Automate en:
https://medium.com/anyone-can-automate/

Proud to be a Flownaut!



Highlighted
Community Support
Community Support

Re: Convert string to currency

Hi @Mattw112IG ,

 

You can create an Excel file online in SharePoint, like this:

Annotation 2019-07-19 182900.png

Then create a flow to update the excel file using the function DOLLAR:

=DOLLAR(Number,2)

After that, create get a row to get the converted number.

 

Annotation 2019-07-19 181557.png

This is a screenshot of the successful result:

Annotation 2019-07-19 181743.png

Please have a try, I hope it can help you.

 

Best Regards,

Community Support Team _ Barry
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Highlighted
Post Prodigy
Post Prodigy

Re: Convert string to currency

@ v-bacao-msft, thanks this works for me.  Would be nic eif I could just do it all self contained within the flow but works for now.

 

@efialttes,@degvalentine - thanks.  I would prefer to use your formula but needs to support over a million.

 

Thanks,

Terry

Highlighted
Advocate V
Advocate V

Re: Convert string to currency

Challenge accepted!

 

I expanded my absurd expression to include values under 1 trillion and posted it to Format number with thousands separator in Flow email, where I originally put my solution.

View solution in original post

Highlighted
Post Prodigy
Post Prodigy

Re: Convert string to currency

I am having an error with the code you did.

When I have a record that has "0" in the field to pass to your formula then I get the error:

 

"InvalidTemplate. Unable to process template language expressions in action 'Compose_-_Dif' inputs at line '1' and column '2623': 'The template language function 'substring' parameters are out of range: 'start index' and 'length' must be non-negative integers and their sum must be no larger than the length of the string. Please see https://aka.ms/logicexpressions#substring for usage details.'."

 

Does this mean your formula is expecting a certain # of characters?

THanks,

Terry

Highlighted
Advocate V
Advocate V

Re: Convert string to currency

Thanks, @Mattw112IG. I posted a fix on the source thread.

Highlighted
Advocate V
Advocate V

Re: Convert string to currency

Please be aware that Flow added the formatNumber function! A locale-specific solution with commas and rounding is easy.

 

formatNumber(1234.567, 'N', 'en-US')

 

 

https://flow.microsoft.com/en-us/blog/simplified-number-formatting/

https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings#the-curr...

 

If you have a string value you might need to cast it first using "float()".

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

Power Platform ISV Studio

Power Platform ISV Studio

ISV Studio is designed to become the go-to Power Platform destination for ISV’s to monitor & manage published applications.

Upcoming Events

Experience what’s next for Power Automate

See the latest Power Automate innovations, updates, and demos from the Microsoft Business Applications Launch Event.

Top Solution Authors
Top Kudoed Authors
Users online (6,912)