How can I convert a value in cents to a dollar value - coldfusion

When I capture my data I am saving the value in cents so $10.00 would be 1000
When I display the value again I want to display it like 10.00
I have tried various different ways like:
#decimalformat(itemprice)#
#NumberFormat(itemprice, '9.99')#
#LSCurrencyFormat(itemprice, "none")#
#DollarFormat(itemprice)#
But every time I end up with 1000.00
Is there any way in ColdFusion to achieve this or should I rather be saving the value in dollars instead of cents and then convert it to cents where needed?
Thank you in advance

Why don't you do something like this:
<cfdump var="#DollarFormat(itemprice/100)#"><cfabort>

Related

How to conditionally display decimals in a measure in Power BI

Let's say I have a simple measure like this:
SimpleMeasure = MyTable[Column1]/MyTable[Column2]
Is it possible to have the number of displayed decimals dependent on the value? For example, if my measure calculates the number 500, then I don't want to see 500.00 but rather 500. However if my measure calculates 0.56, then I want to see the value displayed like that to two decimal places and not rounded to the number 1.
So a possible visualization table would look like this:
Store SimpleMeasure
00 10
01 18
02 0.67
03 6
Thank you in advance!
IF(
[SimpleMeasure] < 1, FORMAT([SimpleMeasure], "#,##0.##",
FORMAT([SimpleMeasure], "#,##0")
)
You can use the Switch() function. It will return the first True result. Put you values in a DESC order - start with the largest value, then come to a lower and then to the lowerest. For example :
Switch(
True
,[SimpleMeasure]<1,Round([SimpleMeasure],2) -- 0.655->0.66
,[SimpleMeasure]>999,Round([SimpleMeasure],-2) --1044->1000
,[SimpleMeasure]>499,Round([SimpleMeasure],-1) -- 505,5->510
,[SimpleMeasure]>99,Round([SimpleMeasure],0) -- 101,55->102
,[SimpleMeasure]>1,Round([SimpleMeasure],1) -- 99,43->99.4
)
Or/and you can use in the Switch() the Format() function, with or instead of Round() like:
Format([SimpleMeasure],"#,##0.#")
Or
Format(Round([SimpleMeasure],1),"#,##0.#")
-- Both of them Format() will return and show 99,43 as 99,4.
-- Placeholer # returns a digit or nothing.
-- Placegholder 0 returns a digit or 0.
Usage of Format() and Round() depends on your task. But for a selective Fomat you will need the Switch().
Hope, the answer will help you solve the case

Turn dataframe column into list of integers / floats (not string). tolist() not working

So I have dataframe with a column names "expense" that has floating numbers in them like this-
expense
20.00
15.00
3.00
6.00
3.00
2.5
I wanted to turn that into a list. I used temp['expense'].tolist() and I got this-
['$20.00', '$15.00', '$3.00', '$6.00', '$3.00', '$2.50']
which is a list of strings. I want the floating numbers to stay float so I can do math on them later. What can I do to achieve that?
Kind of new to it. So thanks for any help.
Try:
temp['expense'].str[1:].astype(float).tolist()
If every entry in temp['expense'] has a dollar sign, then it should work.

Using MINIF/MAXIF with strings containing numbers?

I want to find the minimum number with given conditions(is writer and is under probation), the below code works if D contains numbers, but how do I do it if the number is a part of a string, like a fraction for example? Like how do I use this formula if numbers in D look like "1/8", "31/688", "21/33", etc?
=MINIFS(D3:D1007, A3:A1007, "Writer", C3:C1007, "Probation")
I already have another formula that I use that calculates a decimal value given the fraction, If the fraction is in cell D21 then it would look like this:
=left(D21,find("/",D21)-1)/(right(D21,len(D21)-find("/",D21)))
but how do I apply this kind of formula in a minif/maxif?
I have attached a picture to show what I mean, what I'm trying to do is to put a formula in the passed/total column of package stats(probation), and it will get the lowest passed/total value out of the ones with that package name and importance level. as you can see, the entire writer package's pass rate is 5/8 because the lowest pass rate out of the writer package 5/8 is the lowest pass rate out people with package=writers and importance = probation. But at the moment I have to enter the 5/8s manually, I want it to be able to get it automatically using the formula I'm trying to figure out above.
try:
=ARRAYFORMULA(MIN(IF((A3:A="writer")*(C3:C="probation"),
IFERROR(REGEXEXTRACT(D3:D, "\d+")/REGEXEXTRACT(D3:D, "/(\d+)"), D3:D), )))
or to return fraction:
=ARRAYFORMULA(VLOOKUP(MIN(IF((A3:A="writer")*(C3:C="probation"),
IFERROR(REGEXEXTRACT(D3:D, "\d+")/REGEXEXTRACT(D3:D, "/(\d+)"), D3:D), )),
{IF((A3:A="writer")*(C3:C="probation"),
IFERROR(REGEXEXTRACT(D3:D, "\d+")/REGEXEXTRACT(D3:D, "/(\d+)"), D3:D), ), D3:D}, 2, 0))
also make sure fractions are formatted as plain text not date

IF statement with concatenate and round in Excel

I am trying to create an IF statement formula in excel that converts minutes to days and hours depending on the amount. Then rounds the value to 1 or 2 decimal points and adds the descriptive text (days, hours, etc) to the end
I have tried the following which converts and adds text but does not round:
=IF(L15>=1440, CONVERT(L15,"min","day") & CONCATENATE(L15," days"),
IF(L15>=60, CONVERT(L15,"min","hr") & CONCATENATE(L15," hours"),
IF(L15<=59, CONVERT(L15,"min","min") & CONCATENATE(L15," mins"))))
I would adjust your formula as follows and based on you wanting to round the final number
=IF(L15>=1440,ROUND(L15/1440,2)&" days",IF(L15>=60,ROUND(L15/60,2)&" hours",ROUND(L15,2)&" minutes"))
the ,2 in the ROUND function tell excel how many decimal places to calculate to. if format is set to general, trailing 0s will not be displayed. If you only want 1 decimal calculation then change the ,2 to ,1.

How to query floatfield in Django?

I have a FloatField which can have values like 22.33405, 33.567 etc. Now, I need to query using only upto 2 places after decimal like below
#find all objects with value equal to 22.33
ModelName.objects.filter(field = 22.33)
Is it possible to do so - can I round off or just take first 2 places after decimal?
thanks
try this
ModelName.objects.filter(field__gte=22.33, field__lt=(22.33 + 0.01))
or
ModelName.objects.filter(field__range=(22.33, 22.33 + 0.01))
range lookup
Not directly. If you need this level of accuracy then you should be using DecimalField.