Skip to content

Add M.Q.Convert.DoubleAsStringWithFormat  #1406

Closed

Description

Is your feature request related to a problem? Please describe.
I print arbitrary floating-point numbers that are arguments to the tests in the katas quite often, and printing them with the default ~15 digits of precision doesn't look particularly good, especially if there are multiple numbers and a narrow space to display the text. Here is the example from the published Single-Qubit Gates kata, task "Prepare Arbitrary State":

image

Describe the solution you'd like
Bring back the function M.Q.Convert.DoubleAsStringWithFormat that used to be available in the classic QDK.

Describe alternatives you've considered
I could modify some of the tests to use "neat" numbers, but that makes the code much more complicated unnecessarily, and sometimes I need specific numbers that I cannot round to 3-4 digits of precision.

Activity

  1. filipw commented on Apr 22, 2024

    @filipw
    Contributor

    I also ran into this problem.

    I think in general it would be good to get some guidance on how display formatting of numerical values is supposed to be done in the new QDK.

  2. tcNickolas commented on Jun 3, 2024

    @tcNickolas
    ContributorAuthor

    I have two possible suggestions for this API:

    • Add M.Q.Convert.DoubleAsStringWithPrecision that would allow only to format a number with a specific number of decimal digits - that's enough for my purposes:
      function DoubleAsStringWithPrecision(a : Double, precision : Int) : String
    • Add M.Q.Convert.DoubleAsStringWithFormat that would take a string second parameter with
      function DoubleAsStringWithFormat(a : Double, fmt : String) : String
      We used to rely on C#-style format strings, but since we've switched to Rust, I think it makes sense to use Rust format strings in this case instead.

    Personally I like the first option more, it's more straightforward, and I can't think of a scenario where I'd use more complicated formatting. Thoughts?

  3. JPark1023 commented on Jun 16, 2024

    @JPark1023
    Contributor

    I can work on this

  4. added a commit that references this issue on Jul 24, 2024
    1122c4a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementneeds triage

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions