PDA

View Full Version : turn scientific to fixed



ramin.lich
18th November 2014, 11:36
hi all
ok this is my code

void MainWindow::on_pushButton_2_clicked()
{
QString b;
float x,y,z;
x=ui->lineEdit_3->text().toLong();
y=ui->lineEdit_4->text().toLong();
z=x*y;
z=(float)z/100;
cout<<fixed;
ui->textBrowser_2->setText(b.setNum(z));

}
i dont know why still show me scientific format in textBrowser?!?
any help will be grateful.

wysota
18th November 2014, 12:27
Try:

ui->textBrowser_2->setText(b.setNum(x*y, 'f'));

ramin.lich
18th November 2014, 12:42
thank you so much.
can you also tell me how can i remove float point for example my output is : 500000.000000
in fact my answer is 5000 and 2 zero before point and 6 zero after point is surplus.
thx.

wysota
18th November 2014, 14:00
Divide by 100 and floor or round to int.

ramin.lich
18th November 2014, 18:16
Thanks again.
i used this but has no effect. ( i mean floor has no effect. divide 100 will makes it better :) )

b.setNum(floor(x*y/100),'f');
whats wrong?

wysota
18th November 2014, 22:25
How do you know it has no effect? floor() converts a real value to an integer value so as a result you are getting an integer.