fork download
  1. #include <iostream>
  2. #include <algorithm>
  3.  
  4. double Sign(double Value){
  5. return Value >= 0 ? 1 : -1;
  6. }
  7.  
  8. double MakeKasuu(double Value){
  9. double S = Sign(Value);
  10. double Val = std::abs(Value);
  11. while (1 <= Val)Val /= 10;
  12. return Val * S;
  13. }
  14. double MakeJissuu(const double& Value,int N){
  15. int T = 1;
  16. for (int i = 0; i < N; i++){
  17. T *= 10;
  18. }
  19.  
  20. return Value*T;
  21. }
  22. double MakeHoge(const double& Value,int N){
  23. int Jisuu = static_cast<int>(Value);
  24. double Kasuu = Value - Jisuu;
  25.  
  26. return MakeKasuu(Jisuu) + MakeJissuu(Kasuu,N);
  27. }
  28.  
  29. int main(){
  30. double V = 0;
  31.  
  32. V = 1.23;
  33. std::cout <<V<<" -> "<< MakeHoge(V,2) << std::endl;
  34. V = 20.24;
  35. std::cout <<V<<" -> "<< MakeHoge(V,2) << std::endl;
  36. V = 2.24;
  37. std::cout <<V<<" -> "<< MakeHoge(V,2) << std::endl;
  38. V = 0.01;
  39. std::cout <<V<<" -> "<< MakeHoge(V,2) << std::endl;
  40.  
  41. return 0;
  42. }
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
1.23 -> 23.1
20.24 -> 24.2
2.24 -> 24.2
0.01 -> 1