mysql查询以基于圆形的特定小数值

时间:2017-08-29 00:16:12

标签: mysql rounding decimal-point

我可以对基于值的特定十进制值进行舍入,我的mysql表中有这些数据:

1122.46
4600
2000.56
5250

我希望查询结果如下:

foreach (var anno in annots)
{
    var a = anno.GetPdfObject().CopyTo(masterPdfDoc);
    PdfAnnotation ano = PdfAnnotation.MakeAnnotation(a);

    var apDict = ano.GetAppearanceDictionary();
    if (apDict == null)
    {
        Console.WriteLine("No appearances.");
        continue;
    }
    foreach (PdfName key in apDict.KeySet())
    {
        Console.WriteLine("Appearance: {0}", key);
        PdfStream value = apDict.GetAsStream(key);
        if (value != null)
        {
            var text = ExtractAnnotationText(value);
            Console.WriteLine("Extracted Text: {0}", text);

            if (text != "")
            {
                var valueString = Encoding.ASCII.GetString(value.GetBytes());
                value.SetData(Encoding.ASCII.GetBytes(valueString.Replace(text, "COMMENT: " + text)));
            }
        }
    }
    masterDocPage.AddAnnotation(ano);
}

public static String ExtractAnnotationText(PdfStream xObject)
{
   PdfResources resources = new PdfResources(xObject.GetAsDictionary(PdfName.Resources));
   ITextExtractionStrategy strategy = new LocationTextExtractionStrategy();

   PdfCanvasProcessor processor = new PdfCanvasProcessor(strategy);
   processor.ProcessContent(xObject.GetBytes(), resources);
   var text = strategy.GetResultantText();
   return text;
}

其中只有.99小数点的值被四舍五入。

2 个答案:

答案 0 :(得分:1)

我能想到的唯一方法是:

SELECT `number` + (FLOOR(`number` + 0.01)-FLOOR(`number`))*0.01

测试它:

5249.99 + (FLOOR(5249.99 + 0.01)-FLOOR(5249.99))*0.01 = 5250

1122.46 + (FLOOR(1122.46 + 0.01)-FLOOR(1122.46))*0.01 = 1122.46

答案 1 :(得分:1)

您可以使用案例:

select number + case when number - floor(number) = .99 then .01 else 0 end