cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Mattw112IG
Level 8

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
Community Support Team
Community Support Team

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.
degvalentine
Level 8

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.

14 REPLIES 14
Highlighted
Super User
Super User

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





If anybody solved your question, remember to mark its post as a solution!

Proud to be a Flownaut!





Mattw112IG
Level 8

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

Super User
Super User

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





If anybody solved your question, remember to mark its post as a solution!

Proud to be a Flownaut!





Mattw112IG
Level 8

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

Super User
Super User

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





If anybody solved your question, remember to mark its post as a solution!

Proud to be a Flownaut!





Super User
Super User

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

 





If anybody solved your question, remember to mark its post as a solution!

Proud to be a Flownaut!





Super User
Super User

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!





If anybody solved your question, remember to mark its post as a solution!

Proud to be a Flownaut!





Mattw112IG
Level 8

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 Smiley Wink

 

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

Super User
Super User

Re: Convert string to currency

@Mattw112IG 

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

Hope this helps

 





If anybody solved your question, remember to mark its post as a solution!

Proud to be a Flownaut!





Community Support Team
Community Support Team

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.
Mattw112IG
Level 8

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

degvalentine
Level 8

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.

Mattw112IG
Level 8

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

degvalentine
Level 8

Re: Convert string to currency

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

Helpful resources

Announcements
firstImage

Microsoft Business Applications Virtual Launch Event

Watch the event on demand for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Power Platform 2019 Release Wave 2 Plan

Power Platform 2019 Release Wave 2 Plan

Features releasing from October 2019 through March 2020.

thirdimage

Flow Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

sixthImage

Power Platform World Tour

Find out where you can attend!

seventhimage

Webinars & Video Gallery

Watch & learn from the Flow Community Video Gallery!

Top Kudoed Authors
Users Online
Currently online: 191 members 4,138 guests
Please welcome our newest community members: