double to wxLongLong conversion (newbie question) Topic is solved

Talk here about issues with one of the components hosted at wxCode, or suggest features for it.
Post Reply
Michal
In need of some credit
In need of some credit
Posts: 5
Joined: Thu Nov 15, 2007 5:15 pm

double to wxLongLong conversion (newbie question)

Post by Michal » Fri Jan 04, 2008 1:48 pm

Hi;
I want to present small double number (lets say 0.0078) in wxGrid cell. But when i type this:

wxLongLong helper;
helper.Assign(0.0078);
SetCellValue(4, 3, helper.ToString());

than cell contain only zero. How to convert double to wxLongLong and avoid truncation? Is it a problem whit cell format?

User avatar
doublemax
Moderator
Moderator
Posts: 14281
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Post by doublemax » Fri Jan 04, 2008 3:47 pm

wxLongLong is an integer type, it can't hold floating point values. Why don't you just use a double?
Use the source, Luke!

Michal
In need of some credit
In need of some credit
Posts: 5
Joined: Thu Nov 15, 2007 5:15 pm

Post by Michal » Fri Jan 04, 2008 4:38 pm

>Why don't you just use a double?

Because you can pass only wxString as third argument of SetCellValue and I can convert double to wxString (or I don't know how)... I don't know any wx class similar to double.

User avatar
doublemax
Moderator
Moderator
Posts: 14281
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Post by doublemax » Fri Jan 04, 2008 5:49 pm

Code: Select all

double v=0.0078f;
wxString s;
s << v;
SetCellValue(4, 3, s); 

alternatively:
SetCellValue(4, 3, wxString::Format(wxT("%f"), v)); 
Last edited by doublemax on Fri Jan 04, 2008 6:22 pm, edited 1 time in total.
Use the source, Luke!

timg
Earned some good credits
Earned some good credits
Posts: 148
Joined: Mon Jan 23, 2006 6:52 pm

Post by timg » Fri Jan 04, 2008 5:50 pm

you can just do it like this:

Code: Select all

mygrid->SetCellValue(4, 3, wxString::Format("%f", mydouble));

Post Reply