Maneesh Godbole wrote:Use DecimalFormat with an appropriate pattern.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Actually you can, but only by using an unconventional rounding mode.A few minutes ago, I wrote:. . . You cannot get 0°F to display as −17.77°C because it isn't. It is −17.78°C.
It does not help the posters to learn if you simply post an answer like that. One can learn best by working out one's own answer.We're all here to learn, so when responding to others, please focus on helping them discover their own solutions, instead of simply providing answers.
Campbell Ritchie wrote:dhrubo bhattacharjee, please read what it says on the contents page for this forum:-
It does not help the posters to learn if you simply post an answer like that. One can learn best by working out one's own answer.We're all here to learn, so when responding to others, please focus on helping them discover their own solutions, instead of simply providing answers.
Please don't be annoyed with me, but I have pulled rank and deleted your post.
Serkan Kilic wrote:Thank you all. I guess i figured out how to do it.Looks like it works...
Float? Never use floats unless some other API forces you to. Use doubles. And wouldn't that method be static?salvin francis wrote:. . .
Yes, that will print -17.78 for 0°F. But only use \n if somebody has told you they require the LF character. In printf, always use %n instead.Serkan Kilic wrote:// ...
Campbell Ritchie wrote:Float? Never use floats unless some other API forces you to. Use doubles. And wouldn't that method be static?
Campbell Ritchie wrote:Becaue that method is a function...
salvin francis wrote:You might need a few better variable names instead of C, F, etc... Read the java conventions here
(...)
There are three kinds of actuaries: those who can count, and those who can't.
Piet Souris wrote:Do you really think that 'fahrenheitValue' makes the code easier to read?
Variable names should be short yet meaningful. The choice of a variable name should be mnemonic- that is, designed to indicate to the casual observer the intent of its use. One-character variable names should be avoided except for temporary "throwaway" variables. Common names for temporary variables are i, j, k, m, and n for integers; c, d, and e for characters.
Naming conventions make programs more understandable by making them easier to read. They can also give information about the function of the identifier-for example, whether it's a constant, package, or class-which can be helpful in understanding the code.
Piet Souris wrote:C and F are very well known symbols for Celcius and Fahrenheit, so I find OP's methods very clear...
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
salvin francis wrote:Another quote from the same site:
...They can also give information about the function of the identifier-for example, whether it's a constant, package, or class-which can be helpful in understanding the code.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:While I'm normally a stickler for following the guidelines, I'm going to side with Piet here....But only just.
Winston Gutkowski wrote:
@salvin: And on that basis I'd say that 'fahrenheitValue' is overkill. You know from the type, and the way it's used, that the variable is a value, so why not just call it 'fahrenheit'?
That is not an acronym (pedant!) and looks to me very prone to misspellings, so I would take a disliking to that variable name.salvin francis wrote:. . . a self made shorter acronym like fahrenht . . .
Campbell Ritchie wrote:That is not an acronym ....
salvin francis wrote:Mr. pedant, do you like C and F ?
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Partially agree.Winston Gutkowski wrote:practically documents itself. And for that, I'm willing to break a convention or two.
There are three kinds of actuaries: those who can count, and those who can't.
Liutauras Vilda wrote:...if to go with C and F, method name would require improve its name to convertFahrenheitToCelsius...
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here