Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nf() produces problematic string-formatting of negative numbers #7046

Closed
1 of 17 tasks
nickmcintyre opened this issue May 16, 2024 · 1 comment · Fixed by #7054
Closed
1 of 17 tasks

nf() produces problematic string-formatting of negative numbers #7046

nickmcintyre opened this issue May 16, 2024 · 1 comment · Fixed by #7054

Comments

@nickmcintyre
Copy link
Member

Most appropriate sub-area of p5.js?

  • Accessibility
  • Color
  • Core/Environment/Rendering
  • Data
  • DOM
  • Events
  • Image
  • IO
  • Math
  • Typography
  • Utilities
  • WebGL
  • Build process
  • Unit testing
  • Internationalization
  • Friendly errors
  • Other (specify if possible)

p5.js version

1.9.3

Web browser and version

Chrome 124.0.6367.208

Operating system

macOS 14.4.1

Steps to reproduce this

Steps:

  1. Call nf() with a negative number and extra left padding.
  2. Display the formatted number.

Snippet:

function setup() {
  createCanvas(400, 400);

  background(220);

  // Format a negative number with
  // extra left padding.
  let num = nf(-123, 5);

  // Style the text.
  textAlign(CENTER, CENTER);
  textSize(32);

  // Display the text.
  text(num, 200, 200); // 0-123
}

Here's the sketch for reference.

After reviewing #5710, it may be worth revisiting the string utility functions as part of p5.js 2.0.

@limzykenneth
Copy link
Member

The example provided, would the expected output be -0123? Often this functionality is used to align numbers, ie. to make sure any number will always display as 4 digits, adding a - to the front will probably throw off the alignment so perhaps -123 is the desired output in the case of negative number?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants