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 8137797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T11:16:43+00:00 2026-06-06T11:16:43+00:00

What is the cleanest, most readable way to String.Format a decimal with the following

  • 0

What is the cleanest, most readable way to String.Format a decimal with the following criteria

  • start with a sign symbol (+ or -)
  • a fixed number of fraction digits
  • no decimal separator
  • right aligned
  • pre-padded with “0”‘s

For example

  • 123,45 would become “+0012345”
  • -1123,45 would become “-0112345”
  • 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-06-06T11:16:45+00:00Added an answer on June 6, 2026 at 11:16 am

    You almost certainly want a Custom numeric format string to pass to the String.Format method.

    The custom format string can contain 2 sections (first for positive, second for negative formatting) for which you can supply the literal + or -. So to format with 7 characters zero padded this is something like:

    String.Format("{0:'+'0000000;'-'0000000}",yourValue);
    

    However, this will truncate a decimal, and so your input gives

    123.45 --> +0000123
    -1123.45 --> -0001123
    

    One simple solution is just multiply your number by 100 (to fix the number of decimal digits to 2) before passing it to the above

    Live example: http://rextester.com/SZR8690 (C# – sorry, but only demo’s the idea)

    This could then be wrapped up into an extension method:

    <Extension()> 
    Public Function ToFixedFormat(ByVal value As Decimal, ByVal numFractionalDigits As Integer)
        Return String.Format("{0:'+'0000000;'-'0000000}",value * Math.Pow(10,numFractionalDigits))
    End Function
    

    Live example: http://rextester.com/LSAAA60214 (VB.NET)

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

Sidebar

Related Questions

What's the cleanest, most effective way to validate decimal numbers in JavaScript? Bonus points
What's the cleanest way of filtering a Python string through an external program? In
What is the cleanest, most reliable way to run a Windows application as a
I'm wondering what's the best, the cleanest and the most simply way to work
Does anyone know if there is a way to convert the following string into
What is the cleanest way to create a comma-separated list of string values from
What would the cleanest way to the following pseudocode be? class Player id name
What is the cleanest and most Pythonic way to get tomorrow's date? There must
What is the best (cleanest, most efficient) way to write saturating addition in C?
What is the cleanest, most ASP.NET MVC3 way, for lack of a better term,

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.