L
L
LittleBuster2016-11-08 10:24:10
C++ / C#
LittleBuster, 2016-11-08 10:24:10

How to set boost::lexical_cast format?

float temp = 22.2f;

string s = boost::lexical_cast<string>(temp);

There are a lot of decimal places in a string, how can I convert it to the %.2f format, so that there are only 2 decimal places?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
tsarevfs, 2016-11-08
@LittleBuster

boost::format is here to help. lexical_cast is not designed for this.

std::string str = boost::str(boost::format("%.2f") % temp);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question