I use omnetpp-4.6 and veins-4a2 to execute my simulation.
I run this code which the variable "ch" corresponds to an id packet. In this example, 46.100 is the packet number 100 for the node 46 in my simulation.
I need to convert it to a float number, I used this method but it gives as result after converting it 46.1 and not 46.100. In my work 46.1 and 46.100 are two different packets.
#include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{
std::string ch = "46.100";
std::cout.setf(std::ios_base::fixed, std::ios_base::floatfield);
std::cout.precision(3);
float var = atof(ch.c_str());
EV <<"The value of var is: " << var << "\n";
}
I displayed all messages in my log file with EV. So, when I use std::cout it displays 46.100 but when I use EV it displays 46.1.
There is a method to convert the float number and have the correct number that I would using EV please?