add 1 to the smalest non zero digit

 

Hi

I have been coding this for some time but can not get a working code, here is the input and the desired output.

input stringoutput double
1.29001.3
125.90126

Thanks

 

Thanks for the hint, but it does not help me much, I could brute force it but I am hoping for an elegant solution :)

 

I was bored stiff, so here goes:

double Add1ToLast(double Value)
{
   int DecPts = 0;
   while (DecPts<10)
   {
      double Mult = MathPow(10,DecPts);
      int Reference = (int)(Value*Mult);
      if (Reference==Value*Mult)
      {
         if (Reference%10==0) // Safeguard against a weird scenario
            Mult = Mult/10;   // e.g. Value of 1.11878 gets 1.118781 ?! @^#*$
         return (Value+1/Mult);
      }
      DecPts++;
   }
   return (-1);
}
 
Seng Joo Thio:

I was bored stiff, so here goes:

Thank you :)

 
samjesse:

Hi

I have been coding this for some time but can not get a working code, here is the input and the desired output.

input stringoutput double
1.29001.3
125.90126

Thanks

What would it be helpful for?
Reason: