xj qian
2024-06-25 58c129e8f21f79396a822eaeadd78edf281b52a0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#pragma once
 
//#include <stdio.h>
//#include <stdlib.h>
//#include <tchar.h>
//#include <memory.h>
#include "system/base.hpp"
#include "xstring.hpp"
#include "wobject/xutil.hpp"
 
class xdouble
{
private:
    double value;
public:
    xdouble(double val = 0) :value(val) {}
    xdouble(int val) :value((double)val) {}
    xdouble(xstring val) :value(val.toDouble()) {}
public:
    operator double() { return value; }
    double toInt() { return (int)value; }
    xstring toString() { return xstring(value); }
    double round(int len)
    {
        wchar_t format[64] = L"#.";
        for (int i = 0; i < len && i<  60; i++)
        {
            format[2+i] = L'#';
        }
        xstring str(value);
        bool del = false;
        xstring str1 = xutil::FormatDecimalString((LPTSTR)str.c_str(), format, del);
        return str1.toDouble();
    }
};