Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6630635
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:26:00+00:00 2026-05-25T22:26:00+00:00

I need to convert a decimal value into something like 0.3 = USDC000000000030 The

  • 0

I need to convert a decimal value into something like

0.3 = USDC000000000030

The code i wrote is as below.

   transactionAmount = String.Format("USDC{0}", ((int)(amount*100)).ToString("D12"));

However, it is working for some values perfectly like the example given above. For other some values it is conversion is wrong for example

0.9 = USDC000000000089

1 = USDC000000000099

1.1 USDC000000000109

Any idea why is it happening so?

Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T22:26:01+00:00Added an answer on May 25, 2026 at 10:26 pm

    You’re probably using double, which for financial values is a huge mistake.

    Use decimal instead, and wash your troubles away.

    To wit:

    decimal amount = 0.3m;
    string s = String.Format("USDC{0:000000000000}", 100 * amount);
    Console.WriteLine(s);
    

    Output:

    USDC000000000030
    

    Note that the language specification states:

    The decimal type is a 128-bit data type suitable for financial and monetary calculations.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to convert a Joda-Time DateTime into a String, in the following format:
I would like to convert a possibly Decimal value prefixed with currency symbol into
Im building a server in python, i need to convert a decimal value to
I have a decimal value (64.17 hours) and need to convert this to a
Need help to convert value of the column Pct_To_Total into John, 0,36 Sophia, 0,29
How do I convert a decimal value to a string of decimal digits (0-9),
I need to convert a user's UTM input (WGS 1984) into Decimal Degrees, preferably
I need to convert a float to a string, but to the sixth decimal.
I need to convert a signed decimal number into a 32 bit little-endian binary
I have a string which holds a decimal value in it and I need

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.