# Tag Info

Accepted

### Difficulty rounding on Greedy in pset1

You'll want to use the round function on that amount*100. Given that it's simply a matter of syntax, I don't mind just telling you. It's as simple as int rounded_number = round(other_number*100); ...
Accepted

It's exactly the issue of lack of rounding. If x is 4.2, for example, x*100 is 419 because 4.2 can't be expressed exactly in binary. It's actually 4.1999999nnnn. When you then multiply by 100 and ...
Accepted

### Pset2 - Readability: How to round a .5 number depending on the 2nd digit after the decimal point

Your problem isn't that round(7.535600) rounds to 8 (It should, and does), but that 7.535600 isn't the correct index value. For that text, I'd expect these values: 96 letter(s) 23 word(s) 1 sentence(...
Accepted

### Still Need Help. Pset1 Geedy with round()

It looks like you have a couple of misconceptions in your code. Mostly, you need to understand how integer math works compared to normal math. For instance, when the content of a float is stored in an ...
Accepted

### PSet1 Cash returning implicitly declaring library function 'roundf' with type 'float (float)'

Have you read the man page for the function? Maybe there's something your should include in your code that isn't there? ;-) If this answers your question, please click on the check mark to accept. ...
Accepted

### Pset1 Cash - Trying to round float value DURING computation and not after

The code seems far more complicated than necessary, but this seems to be because you're trying to handle the imprecise float storage problem unsuccessfully. This can be resolved by simply converting ...
1 vote
Accepted

### How should rounding be handled in pset6 readability?

If you simply use round it will round the expected way (up if it's >= 0.5, down otherwise. Python 3.9.1 (default, Jun 15 2021, 23:45:14) [GCC 9.3.0] on linux Type "help", "copyright&...
1 vote

### Compilation error on function round in greedy.c, pset1

Did you use make? Or did you manually type clang [flags]? If it is the latter you must link the math.h library with the -lm flag.
1 vote
Accepted

### Could someone explain the significance of double round in pset1 "greedy" (less comfortable)?

double is one of the types in C, like int and char. It's a double-precision floating point number. So #include <math.h> double round(double x); means that the function takes a double and ...
1 vote
Accepted

### Number imprecision & Rounding - C\$50 Finance

This answer may help: pset7, cash on index.html sometimes giving many decimals (eg.4882.139999999999) And also this answer on how to implement: https://stackoverflow.com/questions/6036082/call-a-...
1 vote

The point of the exercise has been missed - floats are frequently not precisely stored. If you want to see the problem, try printing cents to a precision of 20 digits after the decimal. Also, for ...
1 vote
Accepted

### Why should I use round in greedy?

You understand the round function correctly, it does round a float to the nearest whole number. The point of the exercise is to understand how floats are stored in the computer and how to adapt to ...
1 vote

### Pset1 greedy.c program error

Did you try using round command after multiplying 4.2 by 100? uma1966

Only top scored, non community-wiki answers of a minimum length are eligible