I'm having a little bit of a hard time figuring out how to move a decimal to the left. I understand I could divide or multiply, but that is not what I want to do. Is there another method? I want the user to type in a number like 0.23 and have it be read 23%
Yes so when the user types in 0.23 it will display 23%. Is there a way without dividing or multiplying? Like moving the decimal? I meant to put move it to the right earier.
I understand I could divide or multiply, but that is not what I want to do.
This would certainly be the most natural way to handle this. Why are you restricting yourself?
Like moving the decimal? I meant to put move it to the right earier.
The decimal could be moved. This would be string manipulation. But your example isn't just moving the decimal; you're removing it.
Aside from doing arithmetic, the only other way I can think of is string manipulation. But what exactly are the requirements here? Should "0.123" be "12.3%" or "12%"? Should some sort of rounding happen for 0.127? Do you care about handling invalid input? What if the user enters "00000.23"? "000001.23"? "-0.23"? Should "0.230" be a different output than "0.23"?
you can certainly move the . around in a stringified version of the number.
this is more expensive (CPU terms) and more convoluted (code terms) ... its doable but questionable. Multiply of doubles is really fast, and display is really slow, so you can't really improve the performance or anything... the act of converting it to text dwarfs the multiply.
Of course if it’s multiplication that’s precluded then just add 0.23 a 100 times. It’s a simple copy and paste exercise on number + number ... and put a % at the end of the cout
I understand I could divide or multiply, but that is not what I want to do.
Why not?
What ... at the end of the day ... are you actually trying to do?
A percentage is just the number of hundredths, so simple arithmetic with fractions says multiply by 100. Input/output will far outweigh any time spent on a single multiplication operation. You can format the output however you like once you've done the multiply.