1/*
2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
4 */
5
6
7#include "FloatValue.h"
8
9#include <stdio.h>
10
11
12FloatValue::FloatValue(const BVariant& value)
13	:
14	fValue(value)
15{
16}
17
18
19FloatValue::~FloatValue()
20{
21}
22
23
24bool
25FloatValue::ToString(BString& _string) const
26{
27	char buffer[128];
28
29	switch (fValue.Type()) {
30		case B_FLOAT_TYPE:
31		{
32			snprintf(buffer, sizeof(buffer), "%f", fValue.ToFloat());
33			break;
34		}
35		case B_DOUBLE_TYPE:
36		{
37			snprintf(buffer, sizeof(buffer), "%g", fValue.ToDouble());
38			break;
39		}
40		default:
41			return false;
42	}
43
44	BString string(buffer);
45	if (string.Length() == 0)
46		return false;
47
48	_string = string;
49	return true;
50}
51
52
53bool
54FloatValue::ToVariant(BVariant& _value) const
55{
56	_value = fValue;
57	return true;
58}
59
60
61bool
62FloatValue::operator==(const Value& other) const
63{
64	const FloatValue* otherFloat = dynamic_cast<const FloatValue*>(&other);
65	return otherFloat != NULL ? fValue == otherFloat->fValue : false;
66}
67