mysql将小数取整,MySQL-如何始终取整小数?

For instance I have the following value:

0.000018

This is 6 decimal places, but I want to round it up the nearest whole 4th decimal place, so that:

0.000018 -> 0.0001

I've played with the round() funcction but if I simply use the round function:

round(0.000018,4) = 0.0000

When dealing with decimals for financial purposes, in this case one needs to round up and charge the customer instead of giving them a freebie! But round() will go round up or down depending on value, I need to consistently round up.

Is there a simple way of doing this?

解决方案

You can use ceil (ceiling). It only rounds up, so you'll have to multiply with 10000, do the ceil and then divide the result again.

So ceil(0.000145* 10000) = ceil(1.45) = 2

Divide back and you'll have 0.0002

EDIT: wait, wut? that doesn't work. I mean FLOOR obviously but the working is the same :D

The manual is on the same page too :)

So floor(0.000145* 10000) = floor(1.45) = 1

Divide back and you'll have 0.0001

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值