我有一个包含以下内容的字符串:2.53,并且我试图将此数字转换为decimal
类型,所以我这样做了:
string value = "2.53";
decimal converted = Convert.ToDecimal(value);
但最终结果是:253
答案 0 :(得分:5)
每种文化的小数点都不同。在您的文化中,这可能是逗号。您可以使用### word.i ###
%module word
%{
#include "word.h"
%}
%include "std_string.i"
%include "std_vector.i"
namespace std {
%template(vectord) vector<double>;
}
%include "word.h"
作为swig -c++ -python word.i
g++ -c -fpic word.cpp word_wrap.cxx -I/usr/include/python2.7
g++ -shared word.o word_wrap.o -o _word.so -lstdc++
作为十进制分隔符:
In [1]: import word
In [2]: w = word.Word('test', 10, [10.2])
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-2-ee2e5c406fd9> in <module>()
----> 1 w = word.Word('test', 10, [10.2])
/home/anarayan/workspace/swig-learn/word.pyc in __init__(self, word, numWords, values)
276
277 def __init__(self, word, numWords, values):
--> 278 this = _word.new_Word(word, numWords, values)
279 try:
280 self.this.append(this)
TypeError: in method 'new_Word', argument 3 of type 'std::vector< double,std::allocator< double > > &'