# Strange Problem with LCDNumber

• I'm having a problem with values after a decimal point in my calculator app. If I want to input "0.01010101", this would happen (in the order of inputs)

@
0

0.0
0.01
0.010
0.0101
0.01010
0.1101
0.11010
0.2101
@

Here's the method generating the values for the calculator, I can't give the whole .cpp file due to size constraints and I had to take out certain redundant parts as well to stay within size.

@
/**

• @brief Calculator::newVal

• @param val - new value to be appended to the current value of the calculator

• @return the new value of the calculator
*/
QString Calculator::newVal(QString val)
{
if(equals)//checks if the equal button was the last one clicked
{
equals = false;//sets it to false
currVal = 0;//resets the current value
}

QString str = qStringFromLongDouble(currVal); //value of the calculator

``````if(decimal)//applies the decimal point
{
if(!str.contains("."))//adds a decimal only if there isn't one already there
str.append(".");
for(long double i = 0; i < leadingZeros; i++)//adds any leading zeros after the decimal or after the last non zero value after the decimal point
str.append("0");

}

if(val.operator ==("0"))//if a zero has been inputted
{
if(currVal==0&&!decimal)//if the currVal is and it doesn't have a decimal, return 0
{
return "0";
}
else
{
str = str.append("0");// adds a zero to the end
currVal*=10;

if(decimal)//if there is a decimal
{
currVal/=10;// undo the multiply by 10 and add 1 to the leading zeros
leadingZeros++;
}

return str;
}
}
/*
*
*the logic followed in this part of the method is the same for the rest of the method
*
*/
else if(val.operator ==("1"))//if one has been inputted
{
if(currVal==0)//check if the current value is zero
{
if(decimal)//check if there is a decimal
{
str.append("1");//add 1 to the end of the value
currVal = str.toDouble();//assign a new current value
leadingZeros=0;//reset the leading zeros
return str;
}
else//otherwise
{
currVal = 1;//simply return 1
return "1";
}
}
else//otherwise
{
str = str.append("1");//add zero to the end
currVal = currVal*10+1;//adds a 1 to the end of the current value

if(decimal)//if it's a decimal
{
currVal/=10;//remove the multiply by ten
leadingZeros=0;//reset the leading zeros
}

return str;
}
}
else if(val.operator ==("2"))
{
if(currVal==0)
{
if(decimal)
{
str.append("2");
currVal = str.toDouble();
leadingZeros=0;
return str;
}
else
{
currVal = 2;

return "2";
}
}
else
{
str = str.append("2");
currVal = currVal*10+2;
if(decimal)
{
currVal/=10;
leadingZeros=0;
}
return str;
}
}
else if(val.operator ==("3"))
{
if(currVal==0)
{
if(decimal)
{
str.append("3");
currVal = str.toDouble();
leadingZeros=0;
return str;
}
else
{
currVal = 3;
return "3";
}
}
else
{
str = str.append("3");
currVal = currVal*10+3;
if(decimal)
{
currVal/=10;
leadingZeros=0;
}
return str;
}
}

/**
* Omitted code
**/

return str;
``````

}

@

• It's unclear what all the code you posted has to do with the value displayed in the QLCDNumber.

BTW: What have you set the digitCount property of the QLCDNumber to? It defaults to 5.

• The value displayed before the if/then statements is currVal + any leadingZeros. When it goes through the logic, it determines which value was clicked and then appends it the the end of the current value, which is contained in str.

The digitCount property is set to 12.

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.