Crystal Reports — displaying one decimal in my formula field

自古美人都是妖i 提交于 2020-01-15 12:06:51

问题


I have the following in my formula field:

toText(((Sum ({DataTable1.Ending_Value}, {DataTable1.Name})) - (Sum ({DataTable1.Starting_Value}, {DataTable1.Name})) - (Sum ({DataTable1.Investments}, {DataTable1.Name})) + (Sum ({DataTable1.Proceeds}, {DataTable1.Name})) + (Sum ({DataTable1.Interest_and_Dividends}, {DataTable1.Name})))/(Sum ({DataTable1.Starting_Value}, {DataTable1.Name})) * 100)  + " %"

The output is something like: 6.32 %

Instead of having 2 numbers after the decimal, is there any way to only have 1? I tried the following to no luck:

toText(((Sum ({DataTable1.Ending_Value}, {DataTable1.Name})) - (Sum ({DataTable1.Starting_Value}, {DataTable1.Name})) - (Sum ({DataTable1.Investments}, {DataTable1.Name})) + (Sum ({DataTable1.Proceeds}, {DataTable1.Name})) + (Sum ({DataTable1.Interest_and_Dividends}, {DataTable1.Name})))/((Sum ({DataTable1.Starting_Value}, {DataTable1.Name})) * 100),1)  + " %"

b/c the output kept showing me 0.0 % for everything

Next I tried this:

(toText(((Sum ({DataTable1.Ending_Value}, {DataTable1.Name})) - (Sum ({DataTable1.Starting_Value}, {DataTable1.Name})) - (Sum ({DataTable1.Investments}, {DataTable1.Name})) + (Sum ({DataTable1.Proceeds}, {DataTable1.Name})) + (Sum ({DataTable1.Interest_and_Dividends}, {DataTable1.Name})))/(Sum ({DataTable1.Starting_Value}, {DataTable1.Name})) * 100)  + " %"),1)

No luck with that either.

Anybody have any ideas?


回答1:


Have you tried using the number formatting options you get when you right-click on the field and select 'format object'? It is way easier than trying to get ToText() to do what you want.

Edit: If you want to use ToText(), try using a format string instead of 1 as your second parameter - I think this will do it:

ToText(sum(...) + sum(...), "0.0")



回答2:


I like Ray's solution, but for completeness there is also this hacky method; which quite obviously is the wrong way to go if you also need a currency symbol:

  1. Right-click on the numeric field and select Format.
  2. Go to the Number tab and click Customize.
  3. Click the Currency Symbol tab.
  4. Click Enable Currency Symbol.
  5. Change the Currency Symbol to '%'
  6. Change Position combobox to '-123%'
  7. Click OK, OK to exit and save.



回答3:


Just try this:

  1. Right click on the numeric field.
  2. Click Customize button.
  3. Right the below formula in decimal formula field.

    1 or if <yourfieldname>="condition" then 1 else 2
    
  4. Make sure rounding decimal field is 0.1 or your choice.



来源:https://stackoverflow.com/questions/2836406/crystal-reports-displaying-one-decimal-in-my-formula-field

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!