Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

293
Views
React Speedometer percentage value formatting shows too many decimals

I am using react-d3-speedometer to display speedometers on my React web application but I am running into a problem.

I want to use percentages as values for one of the speedometers but all the number in the svg have about 8 decimals by default. It looks like this: enter image description here

The code I use for this speedometer is as follows:

<ReactSpeedometer
                        maxValue={1}
                        value={0.5924}
                        valueFormat="%"
                        width={250}
                        height={150}
                      />

I assume that this should not be the default behaviour and that I perhaps set a value wrongly, but I cannot find anyone else with this issue on this website or the developers. I hope one of you lovely Stack Overflow people can come to the rescue. Thanks in advance to anyone that answers!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Taken from here: https://github.com/d3/d3-format#locale_format : If the precision is not specified, it defaults to 6 for all types except ​ (none), which defaults to 12.

So you should try it with .2% in the valueFormat to get 2 digits after the dot.

<ReactSpeedometer
                        maxValue={1}
                        value={0.5924}
                        valueFormat=".2%"
                        width={250}
                        height={150}
                      />

Edit: For using different digits i'd go with this

function Speedometer() {
    const value = 0.8;
    return (
        <ReactSpeedometer
            maxValue={1}
            value={value}
            valueFormat=".0%"
            width={250}
            height={150}
            currentValueText={`${value * 100}%`}
        />
    );
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!