function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Tobias HaggeTobias Hagge 

Convert decimal to time (1,8 to 1:48)

Hey, is there a quick solution to this? One way to do it would be leftstring + ':' + rightstring but it seems super messy.

Any ideas?
Best Answer chosen by Tobias Hagge
pconpcon
Are you looking to do this in a formula or in apex?

Formula
LEFT( TEXT(testDecimal__c) , FIND('.', TEXT(testDecimal__c)) - 1) + ':' + RIGHT(TEXT(testDecimal__c), LEN(TEXT(testDecimal__c)) - FIND('.', TEXT(testDecimal__c)))

Apex
String decimalString = String.valueOf(testDecimal);
List<String> decimalParts = decimalString.split('\\.');
String t = decimalParts.get(0) + ':' + decimalParts.get(1);

I don't think there's any cleaner way to do it.

All Answers

pconpcon
Are you looking to do this in a formula or in apex?

Formula
LEFT( TEXT(testDecimal__c) , FIND('.', TEXT(testDecimal__c)) - 1) + ':' + RIGHT(TEXT(testDecimal__c), LEN(TEXT(testDecimal__c)) - FIND('.', TEXT(testDecimal__c)))

Apex
String decimalString = String.valueOf(testDecimal);
List<String> decimalParts = decimalString.split('\\.');
String t = decimalParts.get(0) + ':' + decimalParts.get(1);

I don't think there's any cleaner way to do it.
This was selected as the best answer
Tobias HaggeTobias Hagge
In apex and would have done it the same way, hoped there was a neater way. Thank you!