web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Displaying an Integer ...
Power Apps
Unanswered

Displaying an Integer as a Hexadecimal?

(0) ShareShare
ReportReport
Posted on by 170

Hello, 

 

I though this was a no-brainer, maybe it is and I am missing the obvious, but I have integers in my powerapp canvas form that I need to display as a hexadecimal, but I am not finding anything just the Excel dec2hex.  I am not working with the hex number just displaying. Any ideas?

 

For example 30 =  0x1E

 

Thanks for any help.  -Erik

Categories:
I have the same question (0)
  • Verified answer
    RandyHayes Profile Picture
    76,297 Super User 2024 Season 1 on at

    @ErikH63 

    There is no decimal to hex function in PowerApps unfortunately.  You will have to perform the math in your app to do the conversion.  There are several direct and indirect methods to conversion, so it really depends on what you are up for.  If your numbers will be 2 digit hex (less than 256) then it is pretty straight forward.  If not, then it gets a little challenging.

     

    With({_value: 255,
     _digits:["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"]},
    
     Last(FirstN(_digits, RoundDown(_value / 16 , 0)+1)).Value &
     Last(FirstN(_digits, Mod(_value, 16)+1)).Value
    
    )

    Would provide FF as the result based on the _value of 255.

     

    You can use this and replace the _value with whatever your number is coming from.  Also, this can be used in a component as a function for your app.  Again though, this is all simple hex with decimals less than 256.

     

    I hope this is helpful for you.

  • ErikH63 Profile Picture
    170 on at

    Thank you for confirming that @RandyHayes .   I did seem to find an option in Power Automate flow with "format number".  It is amazing that this function is not in powerapps.  

  • RexMidas Profile Picture
    6 on at

    It might be a bit to late, but I'll post my answer here for future reference.
    If you want to convert any decimal to hex:
    Concat(
    ForAll(
    Sequence(RoundUp(Log(Value(<yourvalue>)+1,16),0),RoundUp(Log(Value(<yourvalue>)+1,16),0),-1),
    {result:Last(FirstN(["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"],(Mod(RoundDown(Value(<yourvalue>)/Power(16,ThisRecord.Value-1),0),16)+1))).Value}),
    result&"")

  • bobesponja Profile Picture
    258 on at

    I'm also late, but here's another solution for folks who are dealing with colors stored as integers that you need converted to hex for HTML elements. The two suggestions given work already, but face problems if you're working with values that don't take up all 6 spaces. The With statement on the outside is just for demo purposes, and you can remove it if you don't need it.

     

     

    With(
     {color:16777215}, // white
     Concat(
     ForAll(
     [RoundDown(color/65536,0),RoundDown(Mod(color,65536)/256,0),RoundDown(Mod(Mod(color,65536),256),0)] As ColorPart,
     Concat(
     ForAll(
     [RoundDown(ColorPart.Value/16,0),RoundDown(Mod(ColorPart.Value,16),0)],
     With({a: Mod(ThisRecord.Value,16)},
     {hex:If(a<10,Text(a),Switch(a,10,"A",11,"B",12,"C",13,"D",14,"E","F"))}
     )
     ),
     hex&""
     )
     ),
     Value
     )
    )

     

    If your data source has a different configuration, like Delphi (which uses BBGGRR instead of RRGGBB), you can just change the order of the elements in the OrderPart array (and if you want RGBA instead, just use the array parts as your RGB portion and set A to whatever you want).

     

    [RoundDown(Mod(Mod(color,65536),256),0),RoundDown(Mod(color,65536)/256,0),RoundDown(color/65536,0)] As ColorPart // BBGGRR version

     

  • HankanmanTM Profile Picture
    2 on at

    //

  • Hankanman Profile Picture
    6 on at

    Old post but I just came up with a super simple way using the JSON() (wasn't available at the time of the original post):

     

    Right(Substitute(JSON(RGBA(0,0,0,0.23)),"""",""),2)

     

    Replace "0.23" with the number you want to convert as a percentage of 255 so 0 returns "00", 1 returns "ff", 0.23 returns "3a"

    For extra style points, you can make it a User-Defined Function:

     

    DecToHex(Decimal:Number):Text = Right(Substitute(JSON(RGBA(0,0,0,Decimal)),"""",""),2);

     

    You can then use this anywhere in the app to get a hex value:

     

    DecToHex(0.23)

     

    This then returns the string "3a" and if you need it in upper case you can simply do:

     

    Upper(DecToHex(0.23))

     

    Which returns "3A"

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 796 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 327 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard