如何用数字求和完整的字符串?

我怎样才能保存数字

这是我的表:

|products| int varchar(10) |id| |num_product| 1 0040 |customers| int varchar(255) |id| |name| |state| 1 ABC 0 2 DEF 0 3 GHI 0 4 JKL 1 

这是控制器:

 def new @customer = Customer.find(params[:id]) @num= Product.first @other_value = Customer.count(:conditions=>['state=0']) end 

这是我的观点:

  

但它返回00403而不是0043 。 我尝试了这个但是我得到的是没有00 403

  

我也试过这个,但不是正确的方法:

  

有人可以帮我这个吗?

你为什么不这样做:

 "%04d" % (@num.num_product.to_i + 1) 

给定@num.num_product #=> "0040"然后:

 "%04d" % ('0040'.to_i + 1) => "0041"