1

I'm trying to solve a problem in racket that I need to get a student's grade and put it inside a star. But if the grade has more than one decimal case I need to round it to show only 1. Ex: If the grade is 8.67 it should show 8.7. But I can't figure how to do it. I tried using:

(round 8.67)

But it goes to closest integer. How can I round to only one decimal?

  • What have you tried? You could check for each decimal case, and round to that case – Bonatti Jul 01 '22 at 21:07
  • 1
    Does this answer your question? [Scheme : precision of decimal numbers](https://stackoverflow.com/questions/10064881/scheme-precision-of-decimal-numbers) – Barmar Jul 01 '22 at 21:10

1 Answers1

1

What would

(round (* 10 8.67))

return?

What would

(/ 10 (round (* 10 8.67)))

return? (or should the ratio be flipped?)

Can you go from here and generalize it to get a working function, by replacing the specific values with symbolic ones, and specifying them as the function's parameters?

(define (nround ten eightSixtySeven)
  ......
  )

Or remove the ten parameter if you want to use the hard-coded value of 10 instead:

(define (round1 eightSixtySeven)
  ...... 10 .....
  )

(define (round2 eightSixtySeven)
  ...... 100 .....
  )

etc.

Will Ness
  • 70,110
  • 9
  • 98
  • 181