跳转到帖子

数字金额大写转换工具 1.0.0

登录关注  

1 Screenshot

About This File

basic_form.h:

#pragma once

class BasicForm : public ui::WindowImplBase
{
public:
	BasicForm();
	~BasicForm();

	virtual std::wstring GetSkinFolder() override;
	virtual std::wstring GetSkinFile() override;
	virtual std::wstring GetWindowClassName() const override;
	bool OnClicked(ui::EventArgs* msg);
	virtual void InitWindow() override;
	virtual LRESULT OnClose(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);

	static const std::wstring kClassName;

	ui::RichEdit* num;
	ui::RichEdit* zh_num;

	std::wstring string2wstring(std::string str);
	std::string wstring2string(std::wstring wstr);
	std::string ChineseCapitalMoney(double Num);
};

basic_form.cpp:

#include "framework.h"
#include "basic_form.h"
#include <string>
#include <cstdlib>
#include <atlstr.h>

const std::wstring BasicForm::kClassName = L"Basic";

BasicForm::BasicForm()
{
}


BasicForm::~BasicForm()
{
}

std::wstring BasicForm::GetSkinFolder()
{
	return L"basic";
}

std::wstring BasicForm::GetSkinFile()
{
	return L"basic.xml";
}

std::wstring BasicForm::GetWindowClassName() const
{
	return kClassName;
}

void BasicForm::InitWindow()
{
	num = (ui::RichEdit*)FindControl(L"num");
	zh_num = (ui::RichEdit*)FindControl(L"zh_num");
	m_pRoot->AttachBubbledEvent(ui::kEventClick, nbase::Bind(&BasicForm::OnClicked, this, std::placeholders::_1));
}


bool BasicForm::OnClicked(ui::EventArgs* msg)
{
	std::wstring name = msg->pSender->GetName();

	if (name == L"do_transe")
	{
		std::string _num = wstring2string(num->GetText());
		double double_num = atof(_num.c_str());
		std::string _cn_num = ChineseCapitalMoney(double_num);
		zh_num->SetText(string2wstring(_cn_num));
	}
	else
	{
	}

	return true;
}


LRESULT BasicForm::OnClose(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
	PostQuitMessage(0L);
	return __super::OnClose(uMsg, wParam, lParam, bHandled);
}



std::wstring BasicForm::string2wstring(std::string str)
{
	std::wstring result;
	int len = MultiByteToWideChar(CP_ACP, 0, str.c_str(), str.size(), NULL, 0);
	TCHAR* buffer = new TCHAR[len + 1];
	MultiByteToWideChar(CP_ACP, 0, str.c_str(), str.size(), buffer, len);
	buffer[len] = '\0';
	result.append(buffer);
	delete[] buffer;
	return result;
}

std::string BasicForm::wstring2string(std::wstring wstr)
{
	std::string result;
	int len = WideCharToMultiByte(CP_ACP, 0, wstr.c_str(), wstr.size(), NULL, 0, NULL, NULL);
	char* buffer = new char[len + 1];
	WideCharToMultiByte(CP_ACP, 0, wstr.c_str(), wstr.size(), buffer, len, NULL, NULL);
	buffer[len] = '\0'; 
	result.append(buffer);
	delete[] buffer;
	return result;

}


std::string BasicForm::ChineseCapitalMoney(double Num)
{
	std::string szChMoney;
	CString szNum;
	int iLen, iNum, iAddZero = 0;
	const char* hzUnit[18] = { "分","角","元","拾","佰","仟","万","拾","佰","仟","亿","拾","佰","仟","万","拾","佰","仟" };
	const char* hzNum[10] = { "零","壹","贰","叁","肆","伍","陆","柒","捌","玖" };
	szNum.Format(_T("%18.0f"), Num * 100); //只是到分
	szNum.TrimLeft();
	iLen = szNum.GetLength();
	if (iLen > 15 || iLen == 0 || Num < 0)return ""; //数据错误返回

	for (int i = 0; i < iLen; i++)
	{
		iNum = _ttoi((LPCTSTR)szNum.Mid(i, 1));
		if (iNum == 0)//如果为0
			iAddZero++;
		else
		{
			if (iAddZero > 0)
				szChMoney += "零";
			szChMoney += hzNum[iNum];//转换为相应的数字
			iAddZero = 0;
		}
		if (iNum != 0 || iLen - i == 3 || iLen - i == 11 || ((iLen - i + 1) % 8 == 0 && iAddZero < 4))
			szChMoney += hzUnit[iLen - i - 1];//添加相应的汉字
	}
	if (szNum.Right(2) == _T("00")) //没有角和分
		szChMoney += "整";
	return szChMoney;
}

 




×
×
  • 创建新的...

重要信息

注册必须使用2-8个中文汉字作为账号